diff --git a/src/api/getReservations.ts b/src/api/getReservations.ts new file mode 100644 index 0000000000000000000000000000000000000000..9f28c7d3455493636f6038ae53fe43de6b6f4f5b --- /dev/null +++ b/src/api/getReservations.ts @@ -0,0 +1,4 @@ +import axios from 'axios'; + +export const getReservations = async (): Promise<any> => + axios('/api/web/reservations/').then((res) => res.data); diff --git a/src/components/Auth/SignInForm/SignInForm.tsx b/src/components/Auth/SignInForm/SignInForm.tsx index 014067d7c675df9ccb60e8982fa18e44f5e04dcd..71825c73f8be5d3b9a8d57840477ec79686a4c07 100644 --- a/src/components/Auth/SignInForm/SignInForm.tsx +++ b/src/components/Auth/SignInForm/SignInForm.tsx @@ -1,10 +1,10 @@ -import React, { FC, useCallback, useContext, useState } from 'react'; +import React, { FC, useContext } from 'react'; import axios from 'axios'; +import { useCookie } from 'hooks/useCookie'; +import { AuthRoutes, NonAuthRoutes } from 'api/routes'; import { SubmitHandler, useForm } from 'react-hook-form'; import { Button } from '@material-ui/core'; import { useHistory } from 'react-router-dom'; -import { AuthRoutes, NonAuthRoutes } from 'api/routes'; -import { fetchCookie } from 'api/fetchCookie'; import { AuthContext } from 'components/Auth/AuthContext'; import { InputField } from 'components/Auth/InputField/InputField'; import { useStyles } from './useStyles'; @@ -18,17 +18,8 @@ const defaultValues = { export const SignInForm: FC = () => { const history = useHistory(); const { setRole, setIsAuth } = useContext(AuthContext); - const [cookie, setCookie] = useState<string>(''); - - useCallback(() => { - let isMounted = true; - if (isMounted) - fetchCookie().then((cookieResponse) => setCookie(cookieResponse)); - return () => { - isMounted = false; - }; - }, [cookie]); + const cookie = useCookie(); const { control, errors, setError, handleSubmit } = useForm<CredentialsType>({ defaultValues, @@ -64,6 +55,8 @@ export const SignInForm: FC = () => { } else if (response.data.status === 'role-choice-needed') { history.replace(`${NonAuthRoutes.auth}${AuthRoutes.choseRole}`); } else if (response.data.status === 'success') { + setRole(response.data.role); + setIsAuth(true); history.replace(`${AuthRoutes.dashboard}${AuthRoutes.home}`); } }); diff --git a/src/components/Dashboard/HomePage/HomePage.tsx b/src/components/Dashboard/HomePage/HomePage.tsx index f472faaa7462563dcbbe01f4af7492996a383fea..94f1eb7c9ed64465e724d768f8aa600096bc90f4 100644 --- a/src/components/Dashboard/HomePage/HomePage.tsx +++ b/src/components/Dashboard/HomePage/HomePage.tsx @@ -109,7 +109,7 @@ export const HomePage: FC = () => { <Grid item container style={{ paddingTop: '20px' }}> <Grid item xs={1} lg={2} /> <Grid item xs={10} lg={8}> - <Reservation /> + <Reservation departure="" destination="" time="" date="" /> </Grid> <Grid item xs={1} lg={2} /> </Grid> diff --git a/src/components/Dashboard/ReservationPage/Reservation/Reservation.tsx b/src/components/Dashboard/ReservationPage/Reservation/Reservation.tsx index 7bdcd177cbe2f0bfa38f73c13a692ebf9b8dbc3d..7b6cc337f071afb84bb3e899001a5a3e1ce195ec 100644 --- a/src/components/Dashboard/ReservationPage/Reservation/Reservation.tsx +++ b/src/components/Dashboard/ReservationPage/Reservation/Reservation.tsx @@ -1,6 +1,7 @@ import React, { FC } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { + Grid, Paper, Table, TableBody, @@ -18,43 +19,45 @@ const useStyles = makeStyles(() => ({ }, })); -function createData( - name: string, - value: string, -): { name: string; value: string } { - return { name, value }; -} - -const rows = [ - createData('From:', 'Via Di Quel Bozen, 45, 39037'), - createData('Date:', '29 / 07 / 2021'), - createData('Time:', '12:15'), - createData('To:', 'Via del Krankenhaus, 7, 39037'), -]; +type ReservationProps = { + departure: string; + destination: string; + time: string; + date: string; +}; -export const Reservation: FC = () => { +export const Reservation: FC<ReservationProps> = ({ + departure, + destination, + time, + date, +}: ReservationProps) => { const classes = useStyles(); return ( - <TableContainer component={Paper}> - <Table aria-label="simple table"> - <TableHead> - <TableRow> - <TableCell>DriveToHospital </TableCell> - </TableRow> - </TableHead> + <Grid item container style={{ paddingTop: '20px' }}> + <Grid item xs={1} lg={2} /> + <Grid item xs={10} lg={8}> + <TableContainer component={Paper}> + <Table aria-label="simple table"> + <TableHead> + <TableRow> + <TableCell>DriveToHospital </TableCell> + </TableRow> + </TableHead> - <TableBody> - {rows.map((row) => ( - <TableRow key={row.name}> - <TableCell component="th" scope="row"> - {row.name} - </TableCell> - <TableCell align="right">{row.value}</TableCell> - </TableRow> - ))} - </TableBody> - </Table> - </TableContainer> + <TableBody> + <TableRow key="departure"> + <TableCell component="th" scope="row"> + Departure + </TableCell> + <TableCell align="right">{departure}</TableCell> + </TableRow> + </TableBody> + </Table> + </TableContainer> + </Grid> + <Grid item xs={1} lg={2} /> + </Grid> ); }; diff --git a/src/components/Dashboard/ReservationPage/ReservationPage.tsx b/src/components/Dashboard/ReservationPage/ReservationPage.tsx index a1672f155d13655f89eda368246cdad5d29f34fe..862eb8e09f1666b4a412ec375fa4c496779ad35a 100644 --- a/src/components/Dashboard/ReservationPage/ReservationPage.tsx +++ b/src/components/Dashboard/ReservationPage/ReservationPage.tsx @@ -21,6 +21,7 @@ import Fab from '@material-ui/core/Fab'; import { NavBar } from 'components/Dashboard/HomePage/NavBar'; import { Reservation } from 'components/Dashboard/ReservationPage/Reservation/Reservation'; +import { useReservations } from 'hooks/useReservations'; let themeResp = createMuiTheme(); themeResp = responsiveFontSizes(themeResp); @@ -86,6 +87,8 @@ export const ReservationPage: FC = () => { const [open, setOpen] = React.useState(false); + const reservation = useReservations(); + const handleClickOpen = (): void => { setOpen(true); }; @@ -210,29 +213,7 @@ export const ReservationPage: FC = () => { <Grid item xs={2} /> </Grid> - <Grid item container style={{ paddingTop: '20px' }}> - <Grid item xs={1} lg={2} /> - <Grid item xs={10} lg={8}> - <Reservation /> - </Grid> - <Grid item xs={1} lg={2} /> - </Grid> - - <Grid item container style={{ paddingTop: '20px' }}> - <Grid item xs={1} lg={2} /> - <Grid item xs={10} lg={8}> - <Reservation /> - </Grid> - <Grid item xs={1} lg={2} /> - </Grid> - - <Grid item container style={{ paddingTop: '20px' }}> - <Grid item xs={1} lg={2} /> - <Grid item xs={10} lg={8}> - <Reservation /> - </Grid> - <Grid item xs={1} lg={2} /> - </Grid> + <Reservation departure="" destination="" time="" date="" /> <Grid item container className={classes.paddingTop}> <Grid item xs={2} /> @@ -244,13 +225,7 @@ export const ReservationPage: FC = () => { <Grid item xs={2} /> </Grid> - <Grid item container style={{ paddingTop: '20px' }}> - <Grid item xs={1} lg={2} /> - <Grid item xs={10} lg={8}> - <Reservation /> - </Grid> - <Grid item xs={1} lg={2} /> - </Grid> + <Reservation departure="" destination="" time="" date="" /> </Grid> </div> ); diff --git a/src/hooks/useReservations.ts b/src/hooks/useReservations.ts new file mode 100644 index 0000000000000000000000000000000000000000..b671101318ae92d15fa2a581f1437abbad35aeb3 --- /dev/null +++ b/src/hooks/useReservations.ts @@ -0,0 +1,16 @@ +import { getReservations } from 'api/getReservations'; +import { getRole } from 'api/getRole'; +import { useEffect, useState } from 'react'; + +export const useReservations = (): any => { + useEffect(() => { + let isMounted = true; + + getReservations().then((data) => console.log(data)); + + return () => { + isMounted = false; + }; + }, []); + return null; +};