From 9a9b2dfc3461fa836b3f31338e45364765b694fb Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 4 Feb 2024 10:14:55 +0530 Subject: [PATCH 1/3] Add validation for doctor experience --- src/Components/Users/UserAdd.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 2c5319e67f..2cacd2c610 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -357,8 +357,20 @@ export const UserAdd = (props: UserProps) => { invalidForm = true; } return; - case "doctor_qualification": case "doctor_experience_commenced_on": + if (state.form.user_type === "Doctor" && !state.form[field]) { + errors[field] = "Field is required"; + invalidForm = true; + } else if ( + state.form.user_type === "Doctor" && + Number(state.form.doctor_experience_commenced_on) > 100 + ) { + errors["doctor_experience_commenced_on"] = + "Doctor experience should be less than 100 years"; + invalidForm = true; + } + return; + case "doctor_qualification": case "doctor_medical_council_registration": if (state.form.user_type === "Doctor" && !state.form[field]) { errors[field] = "Field is required"; From dd15fe4833ad9c5d08e02755bd415f3cf12d5358 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 4 Feb 2024 10:17:13 +0530 Subject: [PATCH 2/3] add auto scroll function to error --- src/Components/Users/UserAdd.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 2cacd2c610..4c63868b19 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -19,6 +19,7 @@ import { classNames, dateQueryString, parsePhoneNumber, + scrollTo, } from "../../Utils/utils"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; @@ -503,6 +504,10 @@ export const UserAdd = (props: UserProps) => { }); if (invalidForm) { dispatch({ type: "set_errors", errors }); + const firstError = Object.keys(errors).find((e) => errors[e]); + if (firstError) { + scrollTo(firstError); + } return false; } dispatch({ type: "set_errors", errors }); From 412286ecf0f9e1fb52cf4a5331d833fd176eef35 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 4 Feb 2024 10:43:00 +0530 Subject: [PATCH 3/3] add max validation for doctor experience in user profile page --- src/Components/Users/UserAdd.tsx | 3 +-- src/Components/Users/UserProfile.tsx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 4c63868b19..b3fc9b830f 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -366,8 +366,7 @@ export const UserAdd = (props: UserProps) => { state.form.user_type === "Doctor" && Number(state.form.doctor_experience_commenced_on) > 100 ) { - errors["doctor_experience_commenced_on"] = - "Doctor experience should be less than 100 years"; + errors[field] = "Doctor experience should be less than 100 years"; invalidForm = true; } return; diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 170de558e4..767fc9b73b 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -244,8 +244,19 @@ export default function UserProfile() { invalidForm = true; } return; - case "doctor_qualification": case "doctor_experience_commenced_on": + if (states.form.user_type === "Doctor" && !states.form[field]) { + errors[field] = "Field is required"; + invalidForm = true; + } else if ( + states.form.user_type === "Doctor" && + Number(states.form.doctor_experience_commenced_on) > 100 + ) { + errors[field] = "Doctor experience should be less than 100 years"; + invalidForm = true; + } + return; + case "doctor_qualification": case "doctor_medical_council_registration": if (states.form.user_type === "Doctor" && !states.form[field]) { errors[field] = "Field is required";