import React, { useEffect } from 'react';
import MailIcon from '@mui/icons-material/Mail';
import InboxIcon from '@mui/icons-material/MoveToInbox';
import {
Box,
Button,
Checkbox,
Divider,
Drawer,
FormControlLabel,
FormGroup,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
TextField,
} from '@mui/material';
import Head from 'next/head';
import { ChevronLeftOutlined } from '@mui/icons-material';
import Loading from 'components/Loading';
import { useFormik } from 'formik';
import { useRouter } from 'next/dist/client/router';
import * as yup from 'yup';
const validationSchema = yup.object({
patient_name: yup
.string('Enter your name')
.min(2, 'Name should be of minimum 2 characters length')
.required('Name is required'),
patient_hkid: yup
.string('Enter your HKID')
.matches(/^[A-Z]{1,2}[0-9]{6}\([0-9]\)$/, 'HKID should be in format of XX123456(1-9)')
.required('HKID is required'),
patient_age: yup
.number('Enter your age')
.min(1, 'Age should be greater than 0')
.max(90, 'Age should be less than 90')
.required('Age is required'),
patient_mobile: yup
.string('Enter your mobile number')
.matches(/^[0-9]{8}$/, 'Mobile number should be 8 numbers')
.required('Mobile number is required'),
});
export default () => {
const [open, setOpen] = React.useState(false);
const [loading, setLoading] = React.useState(true);
const [one_symptoms_selected, setOneSymptomsSelected] = React.useState(false);
const router = useRouter();
const toggleDrawer = newOpen => () => {
setOpen(newOpen);
};
const formik = useFormik({
initialValues: {
patient_name: '',
patient_hkid: '',
patient_age: 0,
patient_mobile: '',
bruisesScratchesMinorBurns: false,
chestPain: false,
headache: false,
myMuiCheck: false,
nauseaAndVomiting: false,
runnyOrStuffyNose: true,
soreThroat: false,
},
validationSchema,
onSubmit: values => {
// alert(JSON.stringify(values, null, 2));
fetch('/api/patient_queue/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ values }),
})
.then(response => response.json())
.then(data => {
if (data.success) {
if (data.queue) {
alert(`registered successfully, will assign you to ${data.queue} queue`);
} else {
alert(`registered successfully`);
}
localStorage.setItem('queue_type', data.queue);
localStorage.setItem('queue_id', data.result.id);
localStorage.setItem('queue_name', data.result.name);
localStorage.setItem('queue_hkid', data.result.hkid);
localStorage.setItem('queue_mobile', data.result.mobile);
localStorage.setItem('queue_description', data.result.description);
router.push('/PatientQueueDisplay');
} else {
// alert(data.message);
alert('sorry there are something wrong, please try again');
}
})
.catch(err => {
console.error(err);
alert('server error');
});
},
});
useEffect(() => {
setOneSymptomsSelected(
!(
formik.values.bruisesScratchesMinorBurns ||
formik.values.chestPain ||
formik.values.headache ||
formik.values.myMuiCheck ||
formik.values.nauseaAndVomiting ||
formik.values.runnyOrStuffyNose ||
formik.values.soreThroat
),
);
}, [formik.values]);
const DrawerList = (
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
{['All mail', 'Trash', 'Spam'].map((text, index) => (