Skip to content

Commit 102c7b4

Browse files
cancel and schedule dynamic
1 parent 7883966 commit 102c7b4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/pages/schedule/ScheduleClassTable/ScheduleClassTableRowHour.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from "react";
1+
import React, { useContext } from "react";
22
import TableCell from "@mui/material/TableCell";
33
import TableRow from "@mui/material/TableRow";
44
import { Button } from "@mui/material";
55
import { ScheduleHour } from "../types";
66
import { tableInnerItemStyle } from "../styles";
7+
import { UserContext } from "../../../context/userContext";
78

89
type ScheduleClassTableRowHourProps = {
910
scheduleHour: ScheduleHour;
@@ -12,8 +13,16 @@ type ScheduleClassTableRowHourProps = {
1213
export function ScheduleClassTableRowHour({
1314
scheduleHour
1415
}: ScheduleClassTableRowHourProps) {
15-
const hasFreeSpots = () => {
16-
return scheduleHour.availableSpots > "0";
16+
const { email } = useContext(UserContext);
17+
18+
const isUserInList = scheduleHour.usersList.includes(email);
19+
20+
const canSchedule = () => {
21+
return scheduleHour.availableSpots > "0" && !isUserInList;
22+
};
23+
24+
const canCancel = () => {
25+
return isUserInList;
1726
};
1827

1928
return (
@@ -24,12 +33,12 @@ export function ScheduleClassTableRowHour({
2433
<TableCell align='center'>{scheduleHour.numberOfSpots}</TableCell>
2534
<TableCell align='center'>{scheduleHour.availableSpots}</TableCell>
2635
<TableCell align='center'>
27-
<Button variant='contained' color='success' disabled={!hasFreeSpots()}>
36+
<Button variant='contained' color='success' disabled={!canSchedule()}>
2837
Schedule
2938
</Button>
3039
</TableCell>
3140
<TableCell align='center'>
32-
<Button variant='outlined' color='error'>
41+
<Button variant='outlined' color='error' disabled={!canCancel()}>
3342
Cancel
3443
</Button>
3544
</TableCell>

src/pages/schedule/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ScheduleHour = {
66
hour: string;
77
numberOfSpots: string;
88
availableSpots: string;
9+
usersList: string[];
910
};
1011

1112
export type ScheduleDay = {

0 commit comments

Comments
 (0)