validation and alrert dialog
This commit is contained in:
parent
133725b7a0
commit
9c7ff223fe
35
src/Components/Helper/AlertDialogBox.tsx
Normal file
35
src/Components/Helper/AlertDialogBox.tsx
Normal file
@ -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 (
|
||||||
|
<Stack spacing={2} sx={{ width: '100%' }}>
|
||||||
|
<Snackbar
|
||||||
|
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||||
|
open={open}
|
||||||
|
autoHideDuration={duration}
|
||||||
|
onClose={handleAlertClose}
|
||||||
|
sx={{ zIndex: 9999 }}
|
||||||
|
>
|
||||||
|
<Alert severity={severity} sx={{ width: '100%' }}>
|
||||||
|
{message}
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AlertDialog;
|
||||||
@ -21,6 +21,7 @@ import RecreationalHobbiesSection7 from './RecreationalHobbiesSection7';
|
|||||||
import OtherDetails8 from './OtherDetails8';
|
import OtherDetails8 from './OtherDetails8';
|
||||||
import PatientImageMarker from '../ImageMarker/PatientImageMarker';
|
import PatientImageMarker from '../ImageMarker/PatientImageMarker';
|
||||||
import ViewPatientImageMarker from '../ImageMarker/ViewPatientImageMarker';
|
import ViewPatientImageMarker from '../ImageMarker/ViewPatientImageMarker';
|
||||||
|
import AlertDialog from '../Helper/AlertDialogBox';
|
||||||
|
|
||||||
const Accordion = styled((props: AccordionProps) => (
|
const Accordion = styled((props: AccordionProps) => (
|
||||||
<MuiAccordion disableGutters elevation={0} square {...props} />
|
<MuiAccordion disableGutters elevation={0} square {...props} />
|
||||||
@ -63,6 +64,7 @@ type Props={
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function PatientForm({type}:Props){
|
export default function PatientForm({type}:Props){
|
||||||
|
const [alertProps, setAlertProps] = React.useState<any>({});
|
||||||
const [expanded, setExpanded] = React.useState<string | false>('panel1');
|
const [expanded, setExpanded] = React.useState<string | false>('panel1');
|
||||||
const [isChecked, setIsChecked] = React.useState(false);
|
const [isChecked, setIsChecked] = React.useState(false);
|
||||||
const [signature,setSignature]=React.useState('');
|
const [signature,setSignature]=React.useState('');
|
||||||
@ -342,7 +344,22 @@ export default function PatientForm({type}:Props){
|
|||||||
setAllPatientData(updatedAllPatientData);
|
setAllPatientData(updatedAllPatientData);
|
||||||
|
|
||||||
localStorage.setItem('patientData', JSON.stringify(newPatientData));
|
localStorage.setItem('patientData', JSON.stringify(newPatientData));
|
||||||
|
|
||||||
|
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();
|
TextFile();
|
||||||
|
}else{
|
||||||
|
setAlertProps({
|
||||||
|
open: true,
|
||||||
|
severity: 'error',
|
||||||
|
message: 'Please fill all the mandatory fields with valid data!',
|
||||||
|
duration: 4000,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const TextFile = () => {
|
const TextFile = () => {
|
||||||
@ -365,11 +382,24 @@ export default function PatientForm({type}:Props){
|
|||||||
setIsChecked(event.target.checked);
|
setIsChecked(event.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAlertClose = () => {
|
||||||
|
setAlertProps({});
|
||||||
|
};
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const patientData = localStorage.getItem('patientData') ? JSON.parse(localStorage.getItem('patientData')) : [];
|
const patientData = localStorage.getItem('patientData') ? JSON.parse(localStorage.getItem('patientData')) : [];
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<>
|
<>
|
||||||
|
{alertProps && alertProps.open && (
|
||||||
|
<AlertDialog
|
||||||
|
open={alertProps.open}
|
||||||
|
message={alertProps.message}
|
||||||
|
severity={alertProps.severity}
|
||||||
|
duration={alertProps.duration}
|
||||||
|
handleAlertClose={handleAlertClose}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Paper elevation={0} className='app-screen-constants'>
|
<Paper elevation={0} className='app-screen-constants'>
|
||||||
<Header/>
|
<Header/>
|
||||||
<Paper elevation={0} sx={{margin:4, minHeight:550}} >
|
<Paper elevation={0} sx={{margin:4, minHeight:550}} >
|
||||||
|
|||||||
@ -136,13 +136,14 @@ export default function PersonalSection({handleFormSection1Data,patientDataDipla
|
|||||||
homePhone: e.target.value,
|
homePhone: e.target.value,
|
||||||
}));
|
}));
|
||||||
}}
|
}}
|
||||||
error={!(/^\d{10}$/.test(patient.homePhone))}
|
// error={!(/^\d{10}$/.test(patient.homePhone))}
|
||||||
helperText={!(/^\d{10}$/.test(patient.homePhone)) ? "Please enter a valid 10-digit phone number" : ""}
|
// helperText={!(/^\d{10}$/.test(patient.homePhone)) ? "Please enter a valid 10-digit phone number" : ""}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={4} className='collapsable-form-style'>
|
<Grid item xs={4} className='collapsable-form-style'>
|
||||||
<TextField
|
<TextField
|
||||||
|
required
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
label="Email"
|
label="Email"
|
||||||
name="email"
|
name="email"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user