diff --git a/src/api/client.ts b/src/api/client.ts index 11785cd..773e8fe 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -38,3 +38,17 @@ export const getAllSessions = (userId: string) => ( axios.get(`/session?userId=${userId}`) as Promise> ).then((response) => response.data); + +export const joinSession = (userId: string, sessionId: string) => + ( + axios.post("/session/join", { userId, sessionId }) as Promise< + AxiosResponse + > + ).then((response) => response.data); + +export const leaveSession = (userId: string, sessionId: string) => + ( + axios.post("/session/leave", { userId, sessionId }) as Promise< + AxiosResponse + > + ).then((response) => response.data); diff --git a/src/pages/SignUp.tsx b/src/pages/SignUp.tsx index d1c840e..b126649 100644 --- a/src/pages/SignUp.tsx +++ b/src/pages/SignUp.tsx @@ -1,32 +1,33 @@ import { Alert, Button, - FormControlLabel, Grid, Paper, - Radio, - RadioGroup, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, Typography, } from "@mui/material"; -import { useContext, useMemo, useState } from "react"; +import { useContext, useMemo } from "react"; import { FormattedDate } from "react-intl"; import { useNavigate } from "react-router"; import { Async } from "react-async"; -import { getAllSessions, type Session } from "../api/client"; +import { + getAllSessions, + joinSession, + leaveSession, + type Session, +} from "../api/client"; import { LoggedInPageContext } from "../context/logged-in-page-context"; export const SignUp = () => { const navigate = useNavigate(); const { userId } = useContext(LoggedInPageContext)!; - const sessionsPromise = useMemo(() => getAllSessions(userId), []) - const [selectedSession, setSelectedSession] = useState(null); + const sessionsPromise = useMemo(() => getAllSessions(userId), []); - const setSelectedSessionFromId = (sessions: Session[], id: string) => setSelectedSession( - sessions.find(s => s.id === id) || null); - - const selectedSessionId = selectedSession && selectedSession.id; - const selectedDate = selectedSession && new Date(selectedSession.date); - const availableSlots = selectedSession && selectedSession?.size - selectedSession.userCount; const availableTokens: number = 0; return ( @@ -47,32 +48,63 @@ export const SignUp = () => { sessions.length === 0 ? ( No sessions are available ) : ( - <> - setSelectedSessionFromId(sessions, e.target.value)} - > - {sessions.map((session) => { - const date = new Date(session.date); - return ( - } - label={ + + + + + Date + Slots + Sign-in/out + + + + {sessions.map((session) => ( + + - } - /> - ); - })} - - - + + + {session.userCount}/{session.size} + + + {session.includesRequester ? ( + + ) : session.userCount >= session.size ? ( + "UNAVAILABLE" + ) : ( + + )} + + + ))} + +
+
) } @@ -81,44 +113,6 @@ export const SignUp = () => { - {selectedDate && ( - - - - - {!availableSlots ? ( - - There are no available slots for this date. - - ) : ( - <> - - There are {availableSlots} available slots for this date. - - - - )} - - )} {!availableTokens && (