From 7047edd6c28bf98e95e1992a199bcdf74eebcdac Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Mon, 22 Jul 2024 15:50:27 +0530 Subject: [PATCH] Revert "show error only when out of focus" This reverts commit 5a33cb78fbe1dcb4c544610ab81fd15b158ec139. --- src/Components/Patient/ManagePatients.tsx | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 6619c5c139f..087bd9af209 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -105,26 +105,45 @@ export const PatientManager = () => { const [showDialog, setShowDialog] = useState<"create" | "list-discharged">(); const [showDoctors, setShowDoctors] = useState(false); const [phone_number, setPhoneNumber] = useState(""); + const [phoneNumberError, setPhoneNumberError] = useState(""); const [emergency_phone_number, setEmergencyPhoneNumber] = useState(""); + const [emergencyPhoneNumberError, setEmergencyPhoneNumberError] = + useState(""); - useEffect(() => { + const setPhoneNum = (phone_number: string) => { + setPhoneNumber(phone_number); if (phone_number.length >= 13) { + setPhoneNumberError(""); updateQuery({ phone_number }); + return; } + if (phone_number === "+91" || phone_number === "") { + setPhoneNumberError(""); qParams.phone_number && updateQuery({ phone_number: null }); + return; } - }, [phone_number]); - useEffect(() => { + setPhoneNumberError("Enter a valid number"); + }; + + const setEmergencyPhoneNum = (emergency_phone_number: string) => { + setEmergencyPhoneNumber(emergency_phone_number); if (emergency_phone_number.length >= 13) { + setEmergencyPhoneNumberError(""); updateQuery({ emergency_phone_number }); + return; } + if (emergency_phone_number === "+91" || emergency_phone_number === "") { + setEmergencyPhoneNumberError(""); qParams.emergency_phone_number && updateQuery({ emergency_phone_number: null }); + return; } - }, [emergency_phone_number]); + + setEmergencyPhoneNumberError("Enter a valid number"); + }; const tabValue = qParams.last_consultation__new_discharge_reason || @@ -976,7 +995,8 @@ export const PatientManager = () => { label="Search by Primary Number" {...queryField("phone_number", "+91")} value={phone_number} - onChange={({ value }) => setPhoneNumber(value)} + onChange={(e) => setPhoneNum(e.value)} + error={phoneNumberError} types={["mobile", "landline"]} className="w-full grow" /> @@ -984,7 +1004,8 @@ export const PatientManager = () => { label="Search by Emergency Number" {...queryField("emergency_phone_number", "+91")} value={emergency_phone_number} - onChange={({ value }) => setEmergencyPhoneNumber(value)} + onChange={(e) => setEmergencyPhoneNum(e.value)} + error={emergencyPhoneNumberError} types={["mobile", "landline"]} className="w-full" />