Skip to content

Commit d19059a

Browse files
call variable schedule request
1 parent ffdb651 commit d19059a

File tree

3 files changed

+45
-71
lines changed

3 files changed

+45
-71
lines changed

src/pages/schedule/ScheduleClassTable/ScheduleClass.tsx

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22

33
import {
44
Typography,
@@ -12,77 +12,28 @@ import {
1212
} from "@mui/material";
1313

1414
import { ScheduleClassTableRowDay } from "./ScheduleClassTableRowDay";
15-
import { ScheduleDay } from "../types";
15+
import { DateWithWeekDay, DayOfTheWeek, ScheduleDay } from "../types";
1616
import { tableHeadItemStyle, tableHeadStyle } from "../../styles";
17-
18-
const scheduleList: ScheduleDay[] = [
19-
{
20-
day: "2021-03-02",
21-
numberOfSpots: "2",
22-
availableSpots: "2",
23-
hours: [
24-
{
25-
hour: "13",
26-
numberOfSpots: "2",
27-
availableSpots: "2"
28-
},
29-
{
30-
hour: "14",
31-
numberOfSpots: "2",
32-
availableSpots: "1"
33-
},
34-
{
35-
hour: "15",
36-
numberOfSpots: "2",
37-
availableSpots: "0"
38-
},
39-
{
40-
hour: "16",
41-
numberOfSpots: "2",
42-
availableSpots: "1"
43-
},
44-
{
45-
hour: "17",
46-
numberOfSpots: "2",
47-
availableSpots: "2"
48-
}
49-
]
50-
},
51-
{
52-
day: "2021-03-03",
53-
numberOfSpots: "2",
54-
availableSpots: "2",
55-
hours: [
56-
{
57-
hour: "13",
58-
numberOfSpots: "2",
59-
availableSpots: "2"
60-
},
61-
{
62-
hour: "14",
63-
numberOfSpots: "2",
64-
availableSpots: "1"
65-
},
66-
{
67-
hour: "15",
68-
numberOfSpots: "2",
69-
availableSpots: "0"
70-
},
71-
{
72-
hour: "16",
73-
numberOfSpots: "2",
74-
availableSpots: "1"
75-
},
76-
{
77-
hour: "17",
78-
numberOfSpots: "2",
79-
availableSpots: "2"
80-
}
81-
]
82-
}
83-
];
17+
import { getSchedulesForAListOfDays } from "../requests";
8418

8519
export function ScheduleClass() {
20+
const listOfDays: DateWithWeekDay[] = [
21+
{ week_day: DayOfTheWeek.MONDAY, date: "2023-04-20" },
22+
{ week_day: DayOfTheWeek.TUESDAY, date: "2023-04-21" }
23+
];
24+
25+
const [schedulesForAListOfDays, setSchedulesForAListOfDays] = useState<
26+
ScheduleDay[]
27+
>([]);
28+
29+
useEffect(() => {
30+
const fetchSchedules = async () => {
31+
setSchedulesForAListOfDays(await getSchedulesForAListOfDays(listOfDays));
32+
};
33+
34+
fetchSchedules();
35+
}, []);
36+
8637
return (
8738
<>
8839
<Typography variant='h3'>Schedule a Class </Typography>
@@ -103,7 +54,7 @@ export function ScheduleClass() {
10354
</TableRow>
10455
</TableHead>
10556
<TableBody>
106-
{scheduleList.map((scheduleDay) => (
57+
{schedulesForAListOfDays.map((scheduleDay) => (
10758
<ScheduleClassTableRowDay
10859
key={scheduleDay.day}
10960
scheduleDay={scheduleDay}

src/pages/schedule/requests.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios";
2-
import { FixedSchedule } from "./types";
2+
import { DateWithWeekDay, FixedSchedule, ScheduleDay } from "./types";
33
import {
44
scheduleCreated,
55
scheduleDeleted
@@ -22,6 +22,24 @@ export const getSchedules = async (): Promise<FixedSchedule[]> => {
2222
return schedules;
2323
};
2424

25+
export const getSchedulesForAListOfDays = async (
26+
listOfDays: DateWithWeekDay[]
27+
): Promise<ScheduleDay[]> => {
28+
let schedules: ScheduleDay[] = [];
29+
30+
await axios
31+
.post(`/variableSchedules/get/forAListOfDays/`, listOfDays)
32+
.then((response) => {
33+
schedules = response.data;
34+
console.log(schedules);
35+
})
36+
.catch((err) => {
37+
console.log(err);
38+
});
39+
40+
return schedules;
41+
};
42+
2543
export const deleteScheduleRequest = async (scheduleId: string) => {
2644
let message: AlertMessage = {
2745
text: "",

src/pages/schedule/types.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export type FixedSchedule = {
3333
users_list: string[];
3434
};
3535

36+
export type DateWithWeekDay = {
37+
week_day: DayOfTheWeek;
38+
date: string;
39+
};
40+
3641
export type FixedSchedulesByDay = {
3742
availableSpots: number;
3843
numberOfSpots: number;

0 commit comments

Comments
 (0)