From 5a512dc5f7ad57a1132e9c05332705a4b3529d13 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Fri, 29 Sep 2023 16:39:26 +0200 Subject: [PATCH] fix(dashboard): edit medical file --- app/src/scenes/Persons/MedicalFile.js | 13 ++++++++----- dashboard/src/scenes/person/components/EditModal.js | 6 +++--- .../scenes/person/components/MedicalFilePrint.js | 5 ++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/scenes/Persons/MedicalFile.js b/app/src/scenes/Persons/MedicalFile.js index 6df333827..3cdfea2f9 100644 --- a/app/src/scenes/Persons/MedicalFile.js +++ b/app/src/scenes/Persons/MedicalFile.js @@ -1,7 +1,6 @@ import React, { useEffect, useMemo, useRef, useState } from 'react'; import styled from 'styled-components'; -import dayjs from 'dayjs'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import { useRecoilValue, useSetRecoilState } from 'recoil'; import { v4 as uuidv4 } from 'uuid'; import ScrollContainer from '../../components/ScrollContainer'; import Button from '../../components/Button'; @@ -28,6 +27,7 @@ import CommentRow from '../Comments/CommentRow'; import NewCommentInput from '../Comments/NewCommentInput'; import { Alert } from 'react-native'; import { formatBirthDateAndAge } from '../../services/dateDayjs'; +import { itemsGroupedByPersonSelector } from '../../recoil/selectors'; const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, editable, onEdit, isUpdateDisabled, backgroundColor, onChange }) => { const organisation = useRecoilValue(organisationState); @@ -39,14 +39,17 @@ const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, e const allConsultations = useRecoilValue(consultationsState); const allTreatments = useRecoilValue(treatmentsState); - const [allMedicalFiles, setAllMedicalFiles] = useRecoilState(medicalFileState); + const setAllMedicalFiles = useSetRecoilState(medicalFileState); const consultations = useMemo(() => (allConsultations || []).filter((c) => c.person === personDB._id), [allConsultations, personDB._id]); const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === personDB._id), [allTreatments, personDB._id]); - const medicalFileDB = useMemo(() => (allMedicalFiles || []).find((m) => m.person === personDB._id), [allMedicalFiles, personDB._id]); - const [medicalFile, setMedicalFile] = useState(medicalFileDB); + const populatedPersons = useRecoilValue(itemsGroupedByPersonSelector); + const populatedPerson = useMemo(() => populatedPersons[personDB?._id] || {}, [populatedPersons, personDB._id]); + + const medicalFileDB = populatedPerson.medicalFile; + const [medicalFile, setMedicalFile] = useState(populatedPerson.medicalFile); const [writingComment, setWritingComment] = useState(''); useEffect(() => { diff --git a/dashboard/src/scenes/person/components/EditModal.js b/dashboard/src/scenes/person/components/EditModal.js index 016f1a4ff..8f557830e 100644 --- a/dashboard/src/scenes/person/components/EditModal.js +++ b/dashboard/src/scenes/person/components/EditModal.js @@ -11,7 +11,7 @@ import { import { outOfBoundariesDate } from '../../../services/date'; import SelectTeamMultiple from '../../../components/SelectTeamMultiple'; import { currentTeamState, userState } from '../../../recoil/auth'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; import CustomFieldInput from '../../../components/CustomFieldInput'; import { useMemo, useState } from 'react'; import ButtonCustom from '../../../components/ButtonCustom'; @@ -31,8 +31,8 @@ export default function EditModal({ person, selectedPanel, onClose, isMedicalFil const team = useRecoilValue(currentTeamState); const [persons, setPersons] = useRecoilState(personsState); const customFieldsMedicalFile = useRecoilValue(customFieldsMedicalFileSelector); - const [allMedicalFiles, setAllMedicalFiles] = useRecoilState(medicalFileState); - const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]); + const setAllMedicalFiles = useSetRecoilState(medicalFileState); + const medicalFile = person.medicalFile; const customFieldsMedicalFileWithLegacyFields = useMemo(() => { const c = [...customFieldsMedicalFile]; diff --git a/dashboard/src/scenes/person/components/MedicalFilePrint.js b/dashboard/src/scenes/person/components/MedicalFilePrint.js index 1237b8e0f..e25b90607 100644 --- a/dashboard/src/scenes/person/components/MedicalFilePrint.js +++ b/dashboard/src/scenes/person/components/MedicalFilePrint.js @@ -7,14 +7,13 @@ import CustomFieldDisplay from '../../../components/CustomFieldDisplay'; import { sortActionsOrConsultations } from '../../../recoil/actions'; import { arrayOfitemsGroupedByConsultationSelector } from '../../../recoil/selectors'; import { treatmentsState } from '../../../recoil/treatments'; -import { medicalFileState, customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles'; +import { customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles'; import { useLocalStorage } from '../../../services/useLocalStorage'; export function MedicalFilePrint({ person }) { const organisation = useRecoilValue(organisationState); const allConsultations = useRecoilValue(arrayOfitemsGroupedByConsultationSelector); const allTreatments = useRecoilValue(treatmentsState); - const allMedicalFiles = useRecoilValue(medicalFileState); const team = useRecoilValue(currentTeamState); const [consultationTypes] = useLocalStorage('consultation-types', []); @@ -39,7 +38,7 @@ export function MedicalFilePrint({ person }) { const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === person._id), [allTreatments, person._id]); - const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]); + const medicalFile = person.medicalFile; return (