From 9c7ff223fec9d27b74e01e55f96a3ebc84e12c49 Mon Sep 17 00:00:00 2001 From: sonika <> Date: Wed, 6 Sep 2023 15:51:30 +0530 Subject: [PATCH] validation and alrert dialog --- src/Components/Helper/AlertDialogBox.tsx | 35 +++++++++++++ src/Components/PatientForm/PatientForm.tsx | 50 +++++++++++++++---- .../PatientForm/PersonalSection1.tsx | 5 +- 3 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 src/Components/Helper/AlertDialogBox.tsx diff --git a/src/Components/Helper/AlertDialogBox.tsx b/src/Components/Helper/AlertDialogBox.tsx new file mode 100644 index 0000000..ad52ec1 --- /dev/null +++ b/src/Components/Helper/AlertDialogBox.tsx @@ -0,0 +1,35 @@ +import { Alert, AlertColor, Snackbar, Stack } from '@mui/material'; + +type Props = { + open: boolean; + message: string; + severity: AlertColor; + duration: number; + handleAlertClose: () => void; +}; + +function AlertDialog({ + open, + message, + severity, + duration, + handleAlertClose, +}: Props) { + return ( + + + + {message} + + + + ); +} + +export default AlertDialog; diff --git a/src/Components/PatientForm/PatientForm.tsx b/src/Components/PatientForm/PatientForm.tsx index 4baaf46..dd6e745 100644 --- a/src/Components/PatientForm/PatientForm.tsx +++ b/src/Components/PatientForm/PatientForm.tsx @@ -21,6 +21,7 @@ import RecreationalHobbiesSection7 from './RecreationalHobbiesSection7'; import OtherDetails8 from './OtherDetails8'; import PatientImageMarker from '../ImageMarker/PatientImageMarker'; import ViewPatientImageMarker from '../ImageMarker/ViewPatientImageMarker'; +import AlertDialog from '../Helper/AlertDialogBox'; const Accordion = styled((props: AccordionProps) => ( @@ -63,6 +64,7 @@ type Props={ } export default function PatientForm({type}:Props){ + const [alertProps, setAlertProps] = React.useState({}); const [expanded, setExpanded] = React.useState('panel1'); const [isChecked, setIsChecked] = React.useState(false); const [signature,setSignature]=React.useState(''); @@ -342,7 +344,22 @@ export default function PatientForm({type}:Props){ setAllPatientData(updatedAllPatientData); localStorage.setItem('patientData', JSON.stringify(newPatientData)); - TextFile(); + + if ( + section1Data.fullName !== "" && section1Data.cellPhone && + /^\d{10}$/.test(section1Data.cellPhone) && section1Data.email && + /^\S+@\S+\.\S+$/.test(section1Data.email) && section1Data.age && + section1Data.age !== "" && Number(section1Data.age) >= 0 && section1Data.mailingAddress && + section1Data.mailingAddress !== "" ){ + TextFile(); + }else{ + setAlertProps({ + open: true, + severity: 'error', + message: 'Please fill all the mandatory fields with valid data!', + duration: 4000, + }); + } }; const TextFile = () => { @@ -356,20 +373,33 @@ export default function PatientForm({type}:Props){ } - const handleExpandChange = - (panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => { - setExpanded(newExpanded ? panel : false); - }; + const handleExpandChange = + (panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => { + setExpanded(newExpanded ? panel : false); + }; - const handleCheckboxChange = (event:any) => { - setIsChecked(event.target.checked); - }; + const handleCheckboxChange = (event:any) => { + setIsChecked(event.target.checked); + }; - //@ts-ignore - const patientData = localStorage.getItem('patientData') ? JSON.parse(localStorage.getItem('patientData')) : []; + const handleAlertClose = () => { + setAlertProps({}); + }; + //@ts-ignore + const patientData = localStorage.getItem('patientData') ? JSON.parse(localStorage.getItem('patientData')) : []; + return( <> + {alertProps && alertProps.open && ( + + )}
diff --git a/src/Components/PatientForm/PersonalSection1.tsx b/src/Components/PatientForm/PersonalSection1.tsx index 44f9888..c7f0755 100644 --- a/src/Components/PatientForm/PersonalSection1.tsx +++ b/src/Components/PatientForm/PersonalSection1.tsx @@ -136,13 +136,14 @@ export default function PersonalSection({handleFormSection1Data,patientDataDipla homePhone: e.target.value, })); }} - error={!(/^\d{10}$/.test(patient.homePhone))} - helperText={!(/^\d{10}$/.test(patient.homePhone)) ? "Please enter a valid 10-digit phone number" : ""} + // error={!(/^\d{10}$/.test(patient.homePhone))} + // helperText={!(/^\d{10}$/.test(patient.homePhone)) ? "Please enter a valid 10-digit phone number" : ""} />