1- import React from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22
33import {
44 Typography ,
@@ -12,77 +12,28 @@ import {
1212} from "@mui/material" ;
1313
1414import { ScheduleClassTableRowDay } from "./ScheduleClassTableRowDay" ;
15- import { ScheduleDay } from "../types" ;
15+ import { DateWithWeekDay , DayOfTheWeek , ScheduleDay } from "../types" ;
1616import { 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
8519export 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 }
0 commit comments