From 6c55944df75f97b0e485807171be87c2f2725375 Mon Sep 17 00:00:00 2001 From: Arjun Sah Date: Tue, 26 Sep 2023 15:55:02 +0545 Subject: [PATCH] #5271 fix annoying alert to confirm duplicate patient --- src/widgets/modalChildren/PatientEditModal.js | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/widgets/modalChildren/PatientEditModal.js b/src/widgets/modalChildren/PatientEditModal.js index 8ddd9be48..da0188aeb 100644 --- a/src/widgets/modalChildren/PatientEditModal.js +++ b/src/widgets/modalChildren/PatientEditModal.js @@ -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 (