diff --git a/dashboard/src/scenes/reception/SelectAndCreatePerson.js b/dashboard/src/scenes/reception/SelectAndCreatePerson.js index 2c0319b7e..271bcbd38 100644 --- a/dashboard/src/scenes/reception/SelectAndCreatePerson.js +++ b/dashboard/src/scenes/reception/SelectAndCreatePerson.js @@ -5,7 +5,7 @@ import { selector, useRecoilState, useRecoilValue } from 'recoil'; import AsyncSelect from 'react-select/async-creatable'; import API from '../../services/api'; import { formatBirthDate, formatCalendarDate } from '../../services/date'; -import { actionsState } from '../../recoil/actions'; +import { TODO, actionsState } from '../../recoil/actions'; import { passagesState } from '../../recoil/passages'; import { rencontresState } from '../../recoil/rencontres'; import { useHistory } from 'react-router-dom'; @@ -23,7 +23,7 @@ function removeDiatricsAndAccents(str) { .replace(/[\u0300-\u036f]/g, ''); } -function personsToOptions(persons, actions, passages, rencontres) { +function personsToOptions(persons, actions, passages, rencontres, urgentActions) { return persons.slice(0, 50).map((person) => ({ value: person._id, label: person.name, @@ -31,6 +31,7 @@ function personsToOptions(persons, actions, passages, rencontres) { lastAction: actions.find((action) => action.person === person._id), lastPassage: passages.find((passage) => passage.person === person._id), lastRencontre: rencontres.find((rencontre) => rencontre.person === person._id), + lastUrgentAction: urgentActions.find((action) => action.person === person._id), })); } @@ -132,14 +133,37 @@ const SelectAndCreatePerson = ({ value, onChange, inputId, classNamePrefix }) => ); }, [rencontres, organisation]); + const lastUrgentActions = useMemo(() => { + return Object.values( + actions + .filter((action) => action.urgent && action.status === TODO) + .reduce((acc, action) => { + if (!acc[action.person] || action.dueAt > acc[action.person].dueAt) { + acc[action.person] = { + name: action.name, + dueAt: action.dueAt, + person: action.person, + }; + } + return acc; + }, {}) + ); + }, [actions]); + return ( { - const options = personsToOptions(filterEasySearch(inputValue, searchablePersons), lastActions, lastPassages, lastRencontres); + const options = personsToOptions( + filterEasySearch(inputValue, searchablePersons), + lastActions, + lastPassages, + lastRencontres, + lastUrgentActions + ); optionsExist.current = options.length; return Promise.resolve(options); }} - defaultOptions={personsToOptions(searchablePersons, lastActions, lastPassages, lastRencontres)} + defaultOptions={personsToOptions(searchablePersons, lastActions, lastPassages, lastRencontres, lastUrgentActions)} name="persons" isMulti isDisabled={isDisabled} @@ -249,11 +273,21 @@ const Person = ({ person }) => { )} -
+
+ { ); }; +const AdditionalInfoRed = ({ label, value }) => { + if (!value) return null; + return ( +
+

⚠️ {label}

+ {value} +
+ ); +}; + export default SelectAndCreatePerson;