Skip to content

Commit

Permalink
fix(OHCS-122): Fix patient update/create state
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Nov 21, 2024
1 parent 1e9f092 commit e3b0615
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
19 changes: 18 additions & 1 deletion src/components/accessories/patientDataForm/PatientDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -193,6 +198,18 @@ const PatientDataForm: FunctionComponent<TProps> = ({
useEffect(() => {
dispatch(getCities());
}, [dispatch, shouldResetForm]);

useEffect(() => {
return () => {
if (mode === "create") {
dispatch(createPatientReset());
} else {
dispatch(updatePatientReset());
}
dispatch(getPatientReset());
};
}, [dispatch]);

const navigate = useNavigate();

const handleCancelEdit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -128,12 +126,7 @@ const EditPatientActivity = () => {
case "TO_DASHBOARD":
return <Navigate to={`${PATHS.patients}`} replace />;
case "TO_PATIENT":
return (
<Navigate
to={`${PATHS.patients_details}/${patient.data?.code}`}
replace
/>
);
return <Navigate to={`${PATHS.patients_details}/${id}`} replace />;
default:
return (
<div data-cy="edit-patient" className="editPatient">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ const NewPatientActivity: FunctionComponent<IOwnProps> = ({
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());
Expand Down

0 comments on commit e3b0615

Please sign in to comment.