55import { useState } from 'react' ;
66import { Box , Grid , Stack , Typography , useTheme } from '@mui/material' ;
77import PageLayout from '../../components/PageLayout' ;
8- import { DesignReview } from 'shared' ;
8+ import { DesignReview , DesignReviewStatus } from 'shared' ;
99import MonthSelector from './CalendarComponents/MonthSelector' ;
1010import CalendarDayCard from './CalendarComponents/CalendarDayCard' ;
1111import FillerCalendarDayCard from './CalendarComponents/FillerCalendarDayCard' ;
12- import {
13- DAY_NAMES ,
14- EnumToArray ,
15- calendarPaddingDays ,
16- daysInMonth ,
17- exampleDesignReview1 ,
18- testDesignReview1
19- } from '../../utils/design-review.utils' ;
12+ import { DAY_NAMES , EnumToArray , calendarPaddingDays , daysInMonth } from '../../utils/design-review.utils' ;
2013import ActionsMenu from '../../components/ActionsMenu' ;
14+ import { useAllDesignReviews } from '../../hooks/design-reviews.hooks' ;
15+ import LoadingIndicator from '../../components/LoadingIndicator' ;
16+ import ErrorPage from '../ErrorPage' ;
17+ import { useCurrentUser } from '../../hooks/users.hooks' ;
18+ import { datePipe } from '../../utils/pipes' ;
2119
2220const CalendarPage = ( ) => {
2321 const theme = useTheme ( ) ;
24-
2522 const [ displayMonthYear , setDisplayMonthYear ] = useState < Date > ( new Date ( ) ) ;
23+ const { isLoading, isError, error, data : designReviews } = useAllDesignReviews ( ) ;
24+ const user = useCurrentUser ( ) ;
25+
26+ if ( isLoading || ! designReviews ) return < LoadingIndicator /> ;
27+ if ( isError ) return < ErrorPage message = { error . message } /> ;
28+
29+ const EventDict = new Map < string , DesignReview [ ] > ( ) ;
2630
27- const EventDict = new Map < Number , DesignReview [ ] > ( ) ;
28- // TODO remove during wire up ticket
29- EventDict . set ( new Date ( ) . getDate ( ) , [ exampleDesignReview1 ] ) ;
30- EventDict . set ( new Date ( ) . getDate ( ) + 3 , [ testDesignReview1 , testDesignReview1 ] ) ;
31- EventDict . set ( new Date ( ) . getDate ( ) + 4 , [ testDesignReview1 , testDesignReview1 , testDesignReview1 ] ) ;
32- const designReviewData : DesignReview [ ] = [ testDesignReview1 , testDesignReview1 ] ;
31+ designReviews . forEach ( ( designReview ) => {
32+ if (
33+ EventDict . has (
34+ datePipe ( new Date ( designReview . dateScheduled . getTime ( ) - designReview . dateScheduled . getTimezoneOffset ( ) * - 60000 ) )
35+ )
36+ ) {
37+ EventDict . set (
38+ datePipe ( designReview . dateScheduled ) ,
39+ EventDict . get (
40+ datePipe ( new Date ( designReview . dateScheduled . getTime ( ) - designReview . dateScheduled . getTimezoneOffset ( ) * - 60000 ) )
41+ ) ! . concat ( designReview )
42+ ) ;
43+ } else {
44+ EventDict . set (
45+ datePipe ( new Date ( designReview . dateScheduled . getTime ( ) - designReview . dateScheduled . getTimezoneOffset ( ) * - 60000 ) ) ,
46+ [ designReview ]
47+ ) ;
48+ }
49+
50+ console . log ( designReview . wbsName ) ;
51+ } ) ;
52+
53+ const unconfirmedDR = designReviews . filter (
54+ ( designReview ) =>
55+ designReview . userCreated . userId === user . userId && designReview . status === DesignReviewStatus . UNCONFIRMED
56+ ) ;
3357
3458 const startOfEachWeek = [ 0 , 7 , 14 , 21 , 28 , 35 ] ;
3559
@@ -40,7 +64,7 @@ const CalendarPage = () => {
4064 const designReviewButtons = ( designReviews : DesignReview [ ] ) => {
4165 return designReviews . map ( ( designReview ) => {
4266 return {
43- title : designReview . designReviewId ,
67+ title : designReview . wbsName ,
4468 onClick : ( ) => { } ,
4569 disabled : false
4670 } ;
@@ -62,7 +86,7 @@ const CalendarPage = () => {
6286 . concat ( paddingArrayEnd . length < 7 ? paddingArrayEnd : [ ] ) ;
6387
6488 const unconfirmedDRSDropdown = (
65- < ActionsMenu title = "My Unconfirmed DRS" buttons = { designReviewButtons ( designReviewData ) } >
89+ < ActionsMenu title = "My Unconfirmed DRS" buttons = { designReviewButtons ( unconfirmedDR ) } >
6690 My Unconfirmed DRs
6791 </ ActionsMenu >
6892 ) ;
@@ -98,7 +122,7 @@ const CalendarPage = () => {
98122 { isDayInDifferentMonth ( day , week ) ? (
99123 < FillerCalendarDayCard day = { day } />
100124 ) : (
101- < CalendarDayCard cardDate = { cardDate } events = { EventDict . get ( cardDate . getDate ( ) ) ?? [ ] } />
125+ < CalendarDayCard cardDate = { cardDate } events = { EventDict . get ( datePipe ( cardDate ) ) ?? [ ] } />
102126 ) }
103127 </ Box >
104128 </ Grid >
0 commit comments