From 1ae0f334ca02401df88d9e3dd5626d3d64b928d2 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Tue, 30 Apr 2024 11:53:02 +0530 Subject: [PATCH] Adds missing required validation for death confirmed doctor in discharge as expired popup (#7683) * Adds missing required validation for death confirmed doctor in discharge as expired popup * fix error * fix error not shown --- src/Components/Facility/DischargeModal.tsx | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index c81ab2cf74e..e2dd14dce79 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -24,6 +24,7 @@ import CircularProgress from "../Common/components/CircularProgress"; import { FacilitySelect } from "../Common/FacilitySelect"; import { FacilityModel } from "./models"; import dayjs from "../../Utils/dayjs"; +import { FieldError } from "../Form/FieldValidators"; interface PreDischargeFormInterface { new_discharge_reason: number | null; @@ -121,15 +122,22 @@ const DischargeModal = ({ if ( preDischargeForm.new_discharge_reason == - DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && - !preDischargeForm.discharge_notes.trim() + DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ) { - setErrors({ - ...errors, - discharge_notes: "Please enter the cause of death", - }); - setIsSendingDischargeApi(false); - return; + const newErrors: Record = {}; + + if (!preDischargeForm.discharge_notes.trim()) { + newErrors["discharge_notes"] = "Please enter the cause of death"; + } + if (!preDischargeForm.death_confirmed_doctor?.trim()) { + newErrors["death_confirmed_doctor"] = "Field is required"; + } + + if (Object.entries(newErrors).length) { + setErrors({ ...errors, ...newErrors }); + setIsSendingDischargeApi(false); + return; + } } const dischargeDetails = { @@ -310,6 +318,7 @@ const DischargeModal = ({ { setPreDischargeForm((form) => {