From 6f712f327dff614dda7af50ef1e0c18d1d6be0f9 Mon Sep 17 00:00:00 2001 From: Steve Tsala <45661418+SteveGT96@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:08:41 +0100 Subject: [PATCH] fix(OHCS-122): Fix patient update/create state (#698) Co-authored-by: SteveGT96 --- .../patientDataForm/PatientDataForm.tsx | 19 ++++++++++++++++++- .../EditPatientActivity.tsx | 15 ++++----------- .../newPatientActivity/NewPatientActivity.tsx | 5 +---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/components/accessories/patientDataForm/PatientDataForm.tsx b/src/components/accessories/patientDataForm/PatientDataForm.tsx index 8d1f02b2b..cc00cddcd 100644 --- a/src/components/accessories/patientDataForm/PatientDataForm.tsx +++ b/src/components/accessories/patientDataForm/PatientDataForm.tsx @@ -22,7 +22,12 @@ import { getFromFields, isFieldSuggested, } from "../../../libraries/formDataHandling/functions"; -import { getCities } from "../../../state/patients"; +import { + createPatientReset, + getCities, + getPatientReset, + updatePatientReset, +} from "../../../state/patients"; import { FIELD_VALIDATION, IState } from "../../../types"; import AutocompleteField from "../autocompleteField/AutocompleteField"; import Button from "../button/Button"; @@ -193,6 +198,18 @@ const PatientDataForm: FunctionComponent = ({ useEffect(() => { dispatch(getCities()); }, [dispatch, shouldResetForm]); + + useEffect(() => { + return () => { + if (mode === "create") { + dispatch(createPatientReset()); + } else { + dispatch(updatePatientReset()); + } + dispatch(getPatientReset()); + }; + }, [dispatch]); + const navigate = useNavigate(); const handleCancelEdit = () => { diff --git a/src/components/activities/editPatientActivity/EditPatientActivity.tsx b/src/components/activities/editPatientActivity/EditPatientActivity.tsx index d291558e1..0e5faeb39 100644 --- a/src/components/activities/editPatientActivity/EditPatientActivity.tsx +++ b/src/components/activities/editPatientActivity/EditPatientActivity.tsx @@ -90,20 +90,18 @@ const EditPatientActivity = () => { useEffect(() => { if (isEmpty(patient.data) && patient.status === "IDLE") { - getPatient(id!); + dispatch(getPatient(id!)); } - }, [patient, id]); + }, [dispatch, patient, id]); useEffect(() => { if (activityTransitionState === "TO_PATIENT") { - getPatient(id!); - updatePatientReset(); setShouldResetForm(true); } else if (activityTransitionState === "TO_KEEP_EDITING") { setOpenConfirmationMessage(false); setActivityTransitionState("IDLE"); } - }, [activityTransitionState, id]); + }, [dispatch, activityTransitionState, id]); useEffect(() => { setOpenConfirmationMessage(hasSucceeded); @@ -128,12 +126,7 @@ const EditPatientActivity = () => { case "TO_DASHBOARD": return ; case "TO_PATIENT": - return ( - - ); + return ; default: return (
diff --git a/src/components/activities/newPatientActivity/NewPatientActivity.tsx b/src/components/activities/newPatientActivity/NewPatientActivity.tsx index 6542af7c5..ee8f43784 100644 --- a/src/components/activities/newPatientActivity/NewPatientActivity.tsx +++ b/src/components/activities/newPatientActivity/NewPatientActivity.tsx @@ -53,10 +53,7 @@ const NewPatientActivity: FunctionComponent = ({ state.patients.createPatient.error?.message || t("common.somethingwrong") ); - const patient = useAppSelector( - (state) => - state.patients.createPatient.data || state.patients.updatePatient.data - ); + const patient = useAppSelector((state) => state.patients.createPatient.data); useEffect(() => { dispatch(getPatientReset());