From 6b4b1aea555e947730e6ed407e3bd2a4400cebd2 Mon Sep 17 00:00:00 2001 From: MiguelMLorente Date: Sun, 7 Dec 2025 16:00:36 +0100 Subject: [PATCH] Create session scheduling page --- src/App.tsx | 2 + src/api/client.ts | 7 ++ src/pages/scheduling/CancellingAction.tsx | 22 ++++++ src/pages/scheduling/SchedulerPage.tsx | 93 +++++++++++++++++++++++ src/pages/scheduling/SchedulingAction.tsx | 37 +++++++++ 5 files changed, 161 insertions(+) create mode 100644 src/pages/scheduling/CancellingAction.tsx create mode 100644 src/pages/scheduling/SchedulerPage.tsx create mode 100644 src/pages/scheduling/SchedulingAction.tsx diff --git a/src/App.tsx b/src/App.tsx index 0163b17..e11d2ad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,6 +10,7 @@ import { BuyReturn } from "./pages/buy/BuyReturn.tsx"; import { Grid, Paper } from "@mui/material"; import { AuthenticatedRoute } from "./pages/auth/AuthenticatedRoute.tsx"; import { InvoicePage } from "./pages/invoice/InvoicePage.tsx"; +import { SchedulerPage } from "./pages/scheduling/SchedulerPage.tsx"; const App = () => ( ( } /> } /> } /> + } /> } /> diff --git a/src/api/client.ts b/src/api/client.ts index 3d74d59..1010996 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -106,3 +106,10 @@ export const getInvoicingSummary = () => AxiosResponse > ).then((response) => response.data); + +export const openSession = (sessionId: string) => + axios.post("/session/open", { sessionId }, getJwtHeader()); +export const closeSession = (sessionId: string) => + axios.post("/session/close", { sessionId }, getJwtHeader()); +export const cancelSession = (sessionId: string) => + axios.post("/session/cancel", { sessionId }, getJwtHeader()); diff --git a/src/pages/scheduling/CancellingAction.tsx b/src/pages/scheduling/CancellingAction.tsx new file mode 100644 index 0000000..02e950e --- /dev/null +++ b/src/pages/scheduling/CancellingAction.tsx @@ -0,0 +1,22 @@ +import { Button } from "@mui/material"; +import { cancelSession, type Session } from "../../api/client"; + +export const CancellingAction = (props: { session: Session }) => { + const { session } = props; + const { status, id } = session; + + if (status === "CANCELLED" || status === "CLOSED") { + return "N/A"; + } + + return ( + + ); +}; diff --git a/src/pages/scheduling/SchedulerPage.tsx b/src/pages/scheduling/SchedulerPage.tsx new file mode 100644 index 0000000..f605f89 --- /dev/null +++ b/src/pages/scheduling/SchedulerPage.tsx @@ -0,0 +1,93 @@ +import { + Grid, + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TablePagination, + TableRow, + Typography, +} from "@mui/material"; +import { FormattedDate } from "react-intl"; +import { getAllSessions, type Session } from "../../api/client"; +import { Async } from "react-async"; +import { useState } from "react"; +import { SchedulingAction } from "./SchedulingAction"; +import { CancellingAction } from "./CancellingAction"; + +export const SchedulerPage = () => { + const sessionsPromise = getAllSessions(); + const [page, setPage] = useState(0); + const rowsPerPage = 10; + + return ( + + > + {(sessions) => ( + + All sessions + + + + + + Date + + + Slots + + + Status + + + Scheduling + + + Cancel + + + + + {sessions + .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) + .map((session) => ( + + + + + + {session.userCount}/{session.size} + + {session.status} + + + + + + + + ))} + +
+
+ setPage(newPage)} + rowsPerPageOptions={[]} + /> +
+ )} + +
+ ); +}; diff --git a/src/pages/scheduling/SchedulingAction.tsx b/src/pages/scheduling/SchedulingAction.tsx new file mode 100644 index 0000000..029cc87 --- /dev/null +++ b/src/pages/scheduling/SchedulingAction.tsx @@ -0,0 +1,37 @@ +import { Button } from "@mui/material"; +import { closeSession, openSession, type Session } from "../../api/client"; + +export const SchedulingAction = (props: { session: Session }) => { + const { session } = props; + const { status, id } = session; + + if (status === "CANCELLED" || status === "CLOSED") { + return ("N/A"); + } + + if (status === "SCHEDULED") { + return ( + + ); + } + + if (status === "OPEN") { + return ( + + ); + } +};