Skip to content

Commit

Permalink
Merge pull request #5332 from msupply-foundation/#5271-unable-to-fill…
Browse files Browse the repository at this point in the history
…-info-due-to-alert

#5271 fix annoying alert to confirm duplicate patient
  • Loading branch information
arjunSussol authored Dec 26, 2023
2 parents 7f4fdd3 + 6c55944 commit 6a3142f
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/widgets/modalChildren/PatientEditModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,34 @@ const PatientEditModalComponent = ({
}) => {
const isFocused = useIsFocused();
const [alertText, setAlertText] = useState(modalStrings.are_you_sure_duplicate_patient);
const [removeModalOpen, toggleRemoveModal] = useToggle();
const [cannotDeleteModalOpen, toggleCannotDeleteModal] = useToggle();
const [canDuplicatePatient, setDuplicatePatient] = useState(false);

let canSave = canSaveForm && canEditPatient;
let canDuplicatePatient = false;

const hasVaccineEvents = hasVaccineEventsForm;
const canDelete = canEditPatient;
const showDelete = !isCreatePatient;

if (canSave && !!surveySchema) {
canSave = surveySchema && surveyForm && nameNoteIsValid;
}

canDuplicatePatient = canSave && isDuplicatePatientLocally && isCreatePatient;
useEffect(() => {
const dateOfBirth = moment(completedForm.dateOfBirth).format('LL');
const name = `${completedForm.firstName} ${completedForm.lastName}`;
const alert = modalStrings.formatString(
modalStrings.are_you_sure_duplicate_patient,
name,
dateOfBirth
);
setAlertText(alert);
if (isDuplicatePatientLocally && isCreatePatient) {
setDuplicatePatient(true);
const dateOfBirth = moment(completedForm.dateOfBirth).format('LL');
const name = `${completedForm.firstName} ${completedForm.lastName}`;
const alert = modalStrings.formatString(
modalStrings.are_you_sure_duplicate_patient,
name,
dateOfBirth
);
setAlertText(alert);
}
}, [isDuplicatePatientLocally]);

const canDelete = canEditPatient;
const showDelete = !isCreatePatient;

const [removeModalOpen, toggleRemoveModal] = useToggle();
const [cannotDeleteModalOpen, toggleCannotDeleteModal] = useToggle();
const onConfirmDuplicatePatient = () => setDuplicatePatient(false);

return (
<ModalContainer
Expand Down Expand Up @@ -160,9 +161,9 @@ const PatientEditModalComponent = ({
<PaperModalContainer isVisible={canDuplicatePatient} onClose={cancelPatientEdit}>
<PaperConfirmModal
questionText={alertText}
confirmText={generalStrings.save}
confirmText={generalStrings.ok}
cancelText={buttonStrings.cancel}
onConfirm={onSaveForm}
onConfirm={onConfirmDuplicatePatient}
onCancel={cancelPatientEdit}
/>
</PaperModalContainer>
Expand Down

0 comments on commit 6a3142f

Please sign in to comment.