From 8bec8bc66d7620efe378cc3c00a76edab449ca36 Mon Sep 17 00:00:00 2001 From: Aditya Jindal Date: Wed, 8 Jan 2025 20:09:15 +0530 Subject: [PATCH] =?UTF-8?q?Fix:=20Replace=20InputWithError=20and=20InputEr?= =?UTF-8?q?rors=20components=20with=20ShadCN=E2=80=99s=20components=20dire?= =?UTF-8?q?ctly.=20(#9847)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/locale/en.json | 1 + .../Patient/PatientRegistration.tsx | 549 ++++++++++-------- src/components/ui/errors.tsx | 11 - src/components/ui/input-with-error.tsx | 24 - .../FacilityOrganizationSelector.tsx | 12 +- .../components/OrganizationSelector.tsx | 69 ++- 6 files changed, 358 insertions(+), 308 deletions(-) delete mode 100644 src/components/ui/errors.tsx delete mode 100644 src/components/ui/input-with-error.tsx diff --git a/public/locale/en.json b/public/locale/en.json index 5008b13f928..3fbcfc3de72 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1632,6 +1632,7 @@ "select": "Select", "select_all": "Select All", "select_date": "Select date", + "select_department": "Select Department", "select_eligible_policy": "Select an Eligible Insurance Policy", "select_facility_for_discharged_patients_warning": "Facility needs to be selected to view discharged patients.", "select_for_administration": "Select for Administration", diff --git a/src/components/Patient/PatientRegistration.tsx b/src/components/Patient/PatientRegistration.tsx index 1dc236f5fb3..94289124403 100644 --- a/src/components/Patient/PatientRegistration.tsx +++ b/src/components/Patient/PatientRegistration.tsx @@ -8,7 +8,6 @@ import SectionNavigator from "@/CAREUI/misc/SectionNavigator"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; -import { InputErrors } from "@/components/ui/errors"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; @@ -49,7 +48,6 @@ import OrganizationSelector from "@/pages/Organization/components/OrganizationSe import { PatientModel, validatePatient } from "@/types/emr/patient"; import Autocomplete from "../ui/autocomplete"; -import InputWithError from "../ui/input-with-error"; interface PatientRegistrationPageProps { facilityId: string; @@ -316,71 +314,93 @@ export default function PatientRegistration(
{t("general_info_detail")}

- - - + + +
+ {errors["name"] && + errors["name"].map((error, i) => ( +
+ {error} +
+ ))} +

- - { - if (e.target.value.length > 13) return; - setForm((f) => ({ - ...f, - phone_number: e.target.value, - emergency_phone_number: samePhoneNumber - ? e.target.value - : f.emergency_phone_number, - })); + + { + if (e.target.value.length > 13) return; + setForm((f) => ({ + ...f, + phone_number: e.target.value, + emergency_phone_number: samePhoneNumber + ? e.target.value + : f.emergency_phone_number, + })); + }} + /> +
+ {errors["phone_number"] && + errors["phone_number"]?.map((error, i) => ( +
+ {error} +
+ ))} +
+ +
+ { + const newValue = !samePhoneNumber; + setSamePhoneNumber(newValue); + if (newValue) { + setForm((f) => ({ + ...f, + emergency_phone_number: f.phone_number, + })); + } }} + id="same-phone-number" /> - -
- - { - const newValue = !samePhoneNumber; - setSamePhoneNumber(newValue); - if (newValue) { - setForm((f) => ({ - ...f, - emergency_phone_number: f.phone_number, - })); - } - }} - id="same-phone-number" - /> - - +

- - { - if (e.target.value.length > 13) return; - setForm((f) => ({ - ...f, - emergency_phone_number: e.target.value, - })); - }} - disabled={samePhoneNumber} - /> - + + + { + if (e.target.value.length > 13) return; + setForm((f) => ({ + ...f, + emergency_phone_number: e.target.value, + })); + }} + disabled={samePhoneNumber} + /> +
+ {errors["emergency_phone_number"] && + errors["emergency_phone_number"]?.map((error, i) => ( +
+ {error} +
+ ))} +
{/*
*/}
- - - setForm((f) => ({ ...f, gender: value })) - } - className="flex items-center gap-4" - > - {GENDER_TYPES.map((g) => ( - - - - + + + + setForm((f) => ({ ...f, gender: value })) + } + className="flex items-center gap-4" + > + {GENDER_TYPES.map((g) => ( + + + + + ))} + +
+ {errors["gender"] && + errors["gender"]?.map((error, i) => ( +
+ {error} +
))} - - +
+
- - - + + + +
+ {errors["blood_group"] && + errors["blood_group"]?.map((error, i) => ( +
+ {error} +
+ ))} +
+
- - - setForm((f) => ({ - ...f, - date_of_birth: `${form.date_of_birth?.split("-")[0] || ""}-${form.date_of_birth?.split("-")[1] || ""}-${e.target.value}`, - })) - } - /> - + + + setForm((f) => ({ + ...f, + date_of_birth: `${form.date_of_birth?.split("-")[0] || ""}-${form.date_of_birth?.split("-")[1] || ""}-${e.target.value}`, + })) + } + />
- - - setForm((f) => ({ - ...f, - date_of_birth: `${form.date_of_birth?.split("-")[0] || ""}-${e.target.value}-${form.date_of_birth?.split("-")[2] || ""}`, - })) - } - /> - + + + setForm((f) => ({ + ...f, + date_of_birth: `${form.date_of_birth?.split("-")[0] || ""}-${e.target.value}-${form.date_of_birth?.split("-")[2] || ""}`, + })) + } + />
- - - setForm((f) => ({ - ...f, - date_of_birth: `${e.target.value}-${form.date_of_birth?.split("-")[1] || ""}-${form.date_of_birth?.split("-")[2] || ""}`, - })) - } - /> - + + + setForm((f) => ({ + ...f, + date_of_birth: `${e.target.value}-${form.date_of_birth?.split("-")[1] || ""}-${form.date_of_birth?.split("-")[2] || ""}`, + })) + } + />
{errors["date_of_birth"] && ( - +
+ {errors["date_of_birth"].map((error, i) => ( +
+ {error} +
+ ))} +
)} @@ -512,25 +564,32 @@ export default function PatientRegistration( {t("age_input_warning_bold")}
- - - setForm((f) => ({ - ...f, - age: e.target.value, - year_of_birth: e.target.value - ? new Date().getFullYear() - Number(e.target.value) - : undefined, - })) - } - type="number" - /> - + + + setForm((f) => ({ + ...f, + age: e.target.value, + year_of_birth: e.target.value + ? new Date().getFullYear() - Number(e.target.value) + : undefined, + })) + } + type="number" + /> +
+ {errors["year_of_birth"] && + errors["year_of_birth"]?.map((error, i) => ( +
+ {error} +
+ ))} +
+ {form.year_of_birth && (
{t("year_of_birth")} : {form.year_of_birth} @@ -540,68 +599,84 @@ export default function PatientRegistration(
- -