Skip to content

Commit

Permalink
Adds missing required validation for death confirmed doctor in discha…
Browse files Browse the repository at this point in the history
…rge as expired popup (#7683)

* Adds missing required validation for death confirmed doctor in discharge as expired popup

* fix error

* fix error not shown
  • Loading branch information
rithviknishad committed Apr 30, 2024
1 parent 63c90b9 commit 1ae0f33
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, FieldError> = {};

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 = {
Expand Down Expand Up @@ -310,6 +318,7 @@ const DischargeModal = ({
<TextFormField
name="death_confirmed_by"
label="Confirmed By"
error={errors.death_confirmed_doctor}
value={preDischargeForm.death_confirmed_doctor ?? ""}
onChange={(e) => {
setPreDischargeForm((form) => {
Expand Down

0 comments on commit 1ae0f33

Please sign in to comment.