Skip to content

Commit

Permalink
Merge pull request #32 from advanced-computer-lab-2023/task-10,16,17,…
Browse files Browse the repository at this point in the history
…51_FrontAndBack

Task 10,16,17,51 front and back
  • Loading branch information
3laaHisham authored Nov 14, 2023
2 parents 44c54df + b7cd577 commit 4963b0d
Show file tree
Hide file tree
Showing 55 changed files with 31,228 additions and 47,034 deletions.
22,888 changes: 22,888 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"@mui/icons-material": "^5.14.16",
"@mui/lab": "^5.0.0-alpha.147",
"@mui/material": "^5.14.17",
"@mui/styled-engine": "^5.14.17",
"@mui/utils": "^5.14.17",
"@pdftron/webviewer": "^10.5.1",
"@react-pdf-viewer/core": "^3.17.0",
"@react-pdf-viewer/core": "^3.12.0",
"apexcharts": "^3.43.0",
"axios": "^1.6.1",
"date-fns": "^2.30.0",
Expand Down
7 changes: 7 additions & 0 deletions client/public/assets/icons/navbar/ic_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/public/assets/icons/navbar/ic_contract.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions client/src/layouts/dashboard/config-navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ const navConfig = [
path: '/blog',
icon: icon('ic_blog')
},
{
title: 'contract',
path: '/contract',
icon: icon('ic_contract')
},
{
title: 'add Slots Or Appointment',
path: '/addSlotsOrAppointment',
icon: icon('ic_add')
},
{
title: 'login',
path: '/login',
Expand Down
17 changes: 17 additions & 0 deletions client/src/pages/addSlotsOrAppointment.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Helmet } from 'react-helmet-async';

import { AddView } from 'src/sections/addSlotsOrAppointment/view';

// ----------------------------------------------------------------------

export default function AddSlotsPage() {
return (
<>
<Helmet>
<title> Add Slots Or Appointment </title>
</Helmet>

<AddView />
</>
);
}
17 changes: 17 additions & 0 deletions client/src/pages/contract.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Helmet } from 'react-helmet-async';

import { DoctorContract } from 'src/sections/contract';

// ----------------------------------------------------------------------

export default function ContarctPage() {
return (
<>
<Helmet>
<title> Contract </title>
</Helmet>

<DoctorContract />
</>
);
}
6 changes: 5 additions & 1 deletion client/src/routes/sections.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const BlogPage = lazy(() => import('src/pages/blog'));
export const UserPage = lazy(() => import('src/pages/user'));
export const DoctorsPage = lazy(() => import('src/pages/doctors'));
export const PatientsPage = lazy(() => import('src/pages/patients'));
export const ContractPage = lazy(() => import('src/pages/contract'));
export const AddSlotsOrAppointmentPage = lazy(() => import('src/pages/addSlotsOrAppointment'));
export const LoginPage = lazy(() => import('src/pages/login'));
export const RegisterPage = lazy(() => import('src/pages/register'));
export const ProductsPage = lazy(() => import('src/pages/products'));
Expand Down Expand Up @@ -52,7 +54,9 @@ export default function Router() {
{ path: 'doctors', element: <DoctorsPage /> },
{ path: 'packages', element: <PackagePage /> },
{ path: 'addFamily', element: <AddFamilyPage /> },
{ path: 'viewPackage', element: <ViewPackagePage /> }
{ path: 'viewPackage', element: <ViewPackagePage /> },
{ path: 'contract', element: <ContractPage /> },
{ path: 'addSlotsOrAppointment', element: <AddSlotsOrAppointmentPage /> }
]
},
{
Expand Down
145 changes: 145 additions & 0 deletions client/src/sections/addSlotsOrAppointment/AddSlots.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { Box, Container, Card, Stack, TextField, Typography, Button, MenuItem, Snackbar, IconButton } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import { axiosInstance } from '../../utils/axiosInstance';

const AddSlotsForm = () => {
const { register, handleSubmit, reset, formState: { errors } } = useForm();
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState('');
const [open, setOpen] = useState(false);


const onSubmit = async (data) => {

const timeStringToObject = (timeString) => {
const [hours, minutes] = timeString.split(':');
return { hours: parseInt(hours, 10), minutes: parseInt(minutes, 10) };
};

const slotData = {
day: data.day,
slots: [{
from: timeStringToObject(data.startTime),
to: timeStringToObject(data.endTime),
maxPatients: data.maxPatients
}]
};

setLoading(true);
setMessage('');

try {
const response = await axiosInstance.put('/me/weeklyslots', slotData);

if (response.status === 200) {
setMessage(response.data.message);
reset();
} else {
setMessage(response.data.message || 'An error occurred');
}
} catch (error) {
setMessage(error.response?.data?.message || error.message);
} finally {
setLoading(false);
setOpen(true);
}
};

const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};

const daysOfWeek = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];

return (
<Container maxWidth="sm">
<Box sx={{ mt: 4, mb: 4 }}>
<Card variant="outlined" sx={{ p: 3, width: '100%', maxWidth: 500 }}>
<Typography variant="h6" gutterBottom sx={{ fontWeight: 'bold', color: '#333' }}>
Add Slots
</Typography>

<form onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={2}>
<TextField
select
label="Day of the Week"
{...register('day', { required: 'Day is required' })}
error={Boolean(errors.day)}
helperText={errors.day?.message}
fullWidth
margin="normal"
>
{daysOfWeek.map(day => (
<MenuItem key={day} value={day}>
{day}
</MenuItem>
))}
</TextField>
<TextField
label="Start Time"
type="time"
InputLabelProps={{ shrink: true }}
{...register('startTime', { required: 'Start time is required' })}
error={Boolean(errors.startTime)}
helperText={errors.startTime?.message}
fullWidth
margin="normal"
/>
<TextField
label="End Time"
type="time"
InputLabelProps={{ shrink: true }}
{...register('endTime', { required: 'End time is required' })}
error={Boolean(errors.endTime)}
helperText={errors.endTime?.message}
fullWidth
margin="normal"
/>
<TextField
label="Max Patients"
type="number"
{...register('maxPatients', { required: 'Max patients is required' })}
error={Boolean(errors.maxPatients)}
helperText={errors.maxPatients?.message}
fullWidth
margin="normal"
/>


<Button
type="submit"
variant="contained"
color="inherit"
disabled={loading}
fullWidth
sx={{ mt: 2 }}
>
{loading ? 'Adding...' : 'Add Slots'}
</Button>
</Stack>
</form>

<Snackbar
open={open}
autoHideDuration={6000}
onClose={handleClose}
message={message}
action={
<IconButton size="small" aria-label="close" color="inherit" onClick={handleClose}>
<CloseIcon fontSize="small" />
</IconButton>
}
/>
</Card>
</Box>
</Container>
);
};

export default AddSlotsForm;
112 changes: 112 additions & 0 deletions client/src/sections/addSlotsOrAppointment/ScheduleApp.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { Box, Container, Card, Stack, TextField, Typography, Button, Snackbar, IconButton } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import { axiosInstance } from '../../utils/axiosInstance';

const ScheduleFollowUpForm = () => {
const { register, handleSubmit, reset, formState: { errors } } = useForm();
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState('');
const [open, setOpen] = useState(false);

const onSubmit = async (data) => {
setLoading(true);
setMessage('');

try {
const response = await axiosInstance.post('/me/appointments', {
...data
});

if (response.status === 200) {
setMessage(response.data.message);
reset();
} else {
setMessage(response.data.message || 'An error occurred');
}
} catch (error) {
setMessage(error.response?.data?.message || error.message);
} finally {
setLoading(false);
setOpen(true);
}
};

const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};

return (
<Container maxWidth="sm">
<Box sx={{ mt: 4, mb: 4 }}>
<Card variant="outlined" sx={{ p: 3, width: '100%', maxWidth: 500 }}>
<Typography variant="h6" gutterBottom sx={{ fontWeight: 'bold', color: '#333' }}>
Schedule Follow-Up Appointment
</Typography>

<form onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={2}>
<TextField
label="Patient's Email"
type="email"
{...register('email', { required: 'Patient email is required' })}
error={Boolean(errors.email)}
helperText={errors.email?.message}
fullWidth
margin="normal"
/>
<TextField
label="Start Date"
type="datetime-local"
InputLabelProps={{ shrink: true }}
{...register('startDate', { required: 'Start date is required' })}
error={Boolean(errors.startDate)}
helperText={errors.startDate?.message}
fullWidth
margin="normal"
/>
<TextField
label="End Date"
type="datetime-local"
InputLabelProps={{ shrink: true }}
{...register('endDate', { required: 'End date is required' })}
error={Boolean(errors.endDate)}
helperText={errors.endDate?.message}
fullWidth
margin="normal"
/>
<Button
type="submit"
variant="contained"
color="inherit"
disabled={loading}
fullWidth
sx={{ mt: 2 }}
>
{loading ? 'Scheduling...' : 'Schedule Appointment'}
</Button>
</Stack>
</form>

<Snackbar
open={open}
autoHideDuration={6000}
onClose={handleClose}
message={message}
action={
<IconButton size="small" aria-label="close" color="inherit" onClick={handleClose}>
<CloseIcon fontSize="small" />
</IconButton>
}
/>
</Card>
</Box>
</Container>
);
};

export default ScheduleFollowUpForm;
Loading

0 comments on commit 4963b0d

Please sign in to comment.