Skip to content

Commit

Permalink
show error only when out of focus
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jul 22, 2024
1 parent 7571e68 commit 5a33cb7
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,45 +105,26 @@ 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("");

const setPhoneNum = (phone_number: string) => {
setPhoneNumber(phone_number);
useEffect(() => {
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]);

setPhoneNumberError("Enter a valid number");
};

const setEmergencyPhoneNum = (emergency_phone_number: string) => {
setEmergencyPhoneNumber(emergency_phone_number);
useEffect(() => {
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;
}

setEmergencyPhoneNumberError("Enter a valid number");
};
}, [emergency_phone_number]);

const tabValue =
qParams.last_consultation__new_discharge_reason ||
Expand Down Expand Up @@ -995,17 +976,15 @@ export const PatientManager = () => {
label="Search by Primary Number"
{...queryField("phone_number", "+91")}
value={phone_number}
onChange={(e) => setPhoneNum(e.value)}
error={phoneNumberError}
onChange={({ value }) => setPhoneNumber(value)}
types={["mobile", "landline"]}
className="w-full grow"
/>
<PhoneNumberFormField
label="Search by Emergency Number"
{...queryField("emergency_phone_number", "+91")}
value={emergency_phone_number}
onChange={(e) => setEmergencyPhoneNum(e.value)}
error={emergencyPhoneNumberError}
onChange={({ value }) => setEmergencyPhoneNumber(value)}
types={["mobile", "landline"]}
className="w-full"
/>
Expand Down

0 comments on commit 5a33cb7

Please sign in to comment.