Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OH2-435 | Fix patient update/creation state #698

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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