update jamespong14205,
This commit is contained in:
256
task1/project/003_src/client/pages/SearchCase/index.js
Normal file
256
task1/project/003_src/client/pages/SearchCase/index.js
Normal file
@@ -0,0 +1,256 @@
|
||||
import MenuIcon from '@mui/icons-material/Menu';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { ChevronLeftOutlined } from '@mui/icons-material';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Checkbox,
|
||||
Drawer,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
TextField,
|
||||
} from '@mui/material';
|
||||
import NonUrgentQueueItemCard from 'components/NonUrgentQueueItemCard';
|
||||
import SemiUrgentQueueItemCard from 'components/SemiUrgentQueueItemCard';
|
||||
import { useFormik } from 'formik';
|
||||
import { useRouter } from 'next/dist/client/router';
|
||||
import Head from 'next/head';
|
||||
import * as yup from 'yup';
|
||||
import NoResultFound from './NoResultFound';
|
||||
import PressSearchToStart from './PressSearchToStart';
|
||||
|
||||
const default_init_values = {
|
||||
semi_urgent_case: true,
|
||||
non_urgent_case: true,
|
||||
hkid: '',
|
||||
mobile: '',
|
||||
};
|
||||
|
||||
const validationSchema = yup.object({});
|
||||
|
||||
const search_input_row_sx = {
|
||||
width: '100%',
|
||||
padding: '1rem',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-start',
|
||||
gap: '0.25rem',
|
||||
fontWeight: 'bold',
|
||||
};
|
||||
|
||||
const row_button_sx = {
|
||||
width: '100%',
|
||||
padding: '1rem',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-around',
|
||||
gap: '0.5rem',
|
||||
};
|
||||
|
||||
export default () => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [p_queue, setPQueue] = React.useState([]);
|
||||
const router = useRouter();
|
||||
const [not_search_yet, setNotSearchYet] = React.useState(true);
|
||||
const [changing_page, setChangingPage] = useState(false);
|
||||
|
||||
const toggleDrawer = newOpen => () => {
|
||||
setOpen(newOpen);
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: default_init_values,
|
||||
validationSchema,
|
||||
onSubmit: values => {
|
||||
setNotSearchYet(false);
|
||||
|
||||
fetch('/api/patient_queue/search', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(values),
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
setPQueue(data.patient_queues);
|
||||
formik.setSubmitting(false);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
alert('server error');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const DrawerList = (
|
||||
<Box sx={{ width: 250 }} role='presentation' onClick={toggleDrawer(false)}>
|
||||
<List>
|
||||
<ListItem key='dashboard' disablePadding>
|
||||
<ListItemButton
|
||||
disabled={changing_page}
|
||||
onClick={() => {
|
||||
setChangingPage(true);
|
||||
router.push('/AdminHome');
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<ChevronLeftOutlined />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary='back to dashboard' />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
</List>
|
||||
</Box>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>dashboard - non-urgent case</title>
|
||||
<meta name='description' content='Generated by create next app' />
|
||||
<link rel='icon' href='/favicon.ico' />
|
||||
</Head>
|
||||
|
||||
<Box className='main'>
|
||||
<Box
|
||||
sx={{
|
||||
//
|
||||
display: 'flex',
|
||||
flexDirection: 'flex-start',
|
||||
alignItems: 'center',
|
||||
gap: '1rem',
|
||||
//
|
||||
height: '3rem',
|
||||
}}
|
||||
>
|
||||
<IconButton aria-label='menu' onClick={toggleDrawer(true)}>
|
||||
<MenuIcon />
|
||||
</IconButton>
|
||||
<Box sx={{ fontWeight: 'bold', fontSize: '1.2rem' }}>Search case</Box>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<Box sx={search_input_row_sx}>
|
||||
<Box>Search by case type:</Box>
|
||||
<FormControlLabel
|
||||
control={<Checkbox sx={{ padding: '0.25rem 1rem' }} size='small' />}
|
||||
label='semi-urgent case'
|
||||
checked={formik.values.semi_urgent_case}
|
||||
onChange={() => formik.setFieldValue('semi_urgent_case', !formik.values.semi_urgent_case)}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox sx={{ padding: '0.25rem 1rem' }} size='small' />}
|
||||
label='non-urgent case'
|
||||
checked={formik.values.non_urgent_case}
|
||||
onChange={() => formik.setFieldValue('non_urgent_case', !formik.values.non_urgent_case)}
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={search_input_row_sx}>
|
||||
<TextField
|
||||
fullWidth
|
||||
variant='standard'
|
||||
id='hkid'
|
||||
name='hkid'
|
||||
label='Search by HKID: Please input HKID'
|
||||
size='small'
|
||||
value={formik.values.hkid}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.hkid && Boolean(formik.errors.hkid)}
|
||||
helperText={formik.touched.hkid && formik.errors.hkid}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box sx={search_input_row_sx}>
|
||||
<TextField
|
||||
fullWidth
|
||||
variant='standard'
|
||||
id='mobile'
|
||||
name='mobile'
|
||||
label='Search by Mobile: Please input no.'
|
||||
size='small'
|
||||
value={formik.values.mobile}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.mobile && Boolean(formik.errors.mobile)}
|
||||
helperText={formik.touched.mobile && formik.errors.mobile}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box sx={row_button_sx}>
|
||||
<Button
|
||||
disabled={!formik.dirty || formik.isSubmitting}
|
||||
fullWidth
|
||||
variant='outlined'
|
||||
onClick={() => {
|
||||
setNotSearchYet(true);
|
||||
setPQueue([]);
|
||||
formik.resetForm();
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button
|
||||
// disabled={!(formik.isValid && formik.dirty && !formik.isSubmitting) || changing_page}
|
||||
fullWidth
|
||||
variant='contained'
|
||||
color='primary'
|
||||
type='submit'
|
||||
disabled={!(formik.isValid && formik.dirty && !formik.isSubmitting)}
|
||||
>
|
||||
Search
|
||||
</Button>
|
||||
</Box>
|
||||
</form>
|
||||
</Box>
|
||||
|
||||
<Box style={{ overflowY: 'scroll' }}>
|
||||
{not_search_yet ? (
|
||||
<PressSearchToStart />
|
||||
) : (
|
||||
<>
|
||||
{p_queue.length === 0 ? (
|
||||
<NoResultFound />
|
||||
) : (
|
||||
<>
|
||||
{p_queue.map(queue_data => {
|
||||
if (queue_data.queue_type === 'non-urgent')
|
||||
return (
|
||||
<NonUrgentQueueItemCard key={queue_data} queue_data={queue_data} show_edit_delete={false} />
|
||||
);
|
||||
if (queue_data.queue_type === 'semi-urgent')
|
||||
return (
|
||||
<SemiUrgentQueueItemCard key={queue_data} queue_data={queue_data} show_edit_delete={false} />
|
||||
);
|
||||
|
||||
return <></>;
|
||||
})}
|
||||
<Box
|
||||
style={{
|
||||
width: '100%',
|
||||
display: 'inline-flex',
|
||||
justifyContent: 'center',
|
||||
marginTop: '1rem',
|
||||
marginBottom: '1rem',
|
||||
}}
|
||||
>
|
||||
--end of list--
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Drawer open={open} onClose={toggleDrawer(false)}>
|
||||
{DrawerList}
|
||||
</Drawer>
|
||||
</>
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user