@@ -4,10 +4,7 @@ import { useTranslation } from "next-i18next";
44import { useRouter } from "next/router" ;
55import styled from "styled-components" ;
66import { useFormContext } from "react-hook-form" ;
7- import type {
8- ApplicationEvent ,
9- ApplicationEventSchedulePriority ,
10- } from "common/types/common" ;
7+ import type { ApplicationEventSchedulePriority } from "common/types/common" ;
118import type {
129 ApplicationEventScheduleNode ,
1310 ApplicationNode ,
@@ -35,15 +32,15 @@ type Props = {
3532
3633type OpeningHourPeriod = {
3734 begin : string ;
38- beginValue : number ;
3935 end : string ;
40- endValue : number ;
41- } ;
36+ } | null ;
4237
43- type DailyOpeningHours = {
44- closed : boolean ;
45- reservableTimes ?: OpeningHourPeriod [ ] ;
46- } [ ] ;
38+ type DailyOpeningHours =
39+ | {
40+ closed : boolean ;
41+ reservableTimes ?: OpeningHourPeriod [ ] | null ;
42+ } [ ]
43+ | null ;
4744
4845const SubHeading = styled . p `
4946 margin-top: var(--spacing-2-xs);
@@ -78,14 +75,14 @@ const applicationEventSchedulesToCells = (
7875 const dayOpeningHours =
7976 openingHours ?. [ j ] ?. reservableTimes ?. map ( ( t ) => {
8077 return {
81- beginValue : + t . begin . split ( ":" ) [ 0 ] ,
82- endValue : + t . end . split ( ":" ) [ 0 ] === 0 ? 24 : + t . end . split ( ":" ) [ 0 ] ,
78+ begin : t && + t . begin . split ( ":" ) [ 0 ] ,
79+ end : t && + t . end . split ( ":" ) [ 0 ] === 0 ? 24 : t && + t . end . split ( ":" ) [ 0 ] ,
8380 } ;
8481 } ) ?? [ ] ;
8582 // state is 50 if the cell is outside of the opening hours, 100 if it's inside
8683 for ( let i = firstSlotStart ; i <= lastSlotStart ; i += 1 ) {
8784 const isAvailable = dayOpeningHours . some (
88- ( t ) => t . beginValue <= i && t . endValue > i
85+ ( t ) => t . begin != null && t . end != null && t ?. begin <= i && t ?. end > i
8986 ) ;
9087 day . push ( {
9188 key : `${ i } -${ j } ` ,
@@ -224,15 +221,16 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
224221 QueryApplicationRoundsArgs
225222 > ( RESERVATION_UNIT , {
226223 variables : {
227- pk : application . applicationRound . pk ,
224+ pk : [ application . applicationRound . pk ?? 0 ] ,
228225 } ,
226+ skip : ! application . applicationRound . pk ,
229227 fetchPolicy : "no-cache" ,
230228 } ) ;
231229 const [ successMsg , setSuccessMsg ] = useState ( "" ) ;
232230 const [ errorMsg , setErrorMsg ] = useState ( "" ) ;
233231 const [ minDurationMsg , setMinDurationMsg ] = useState ( true ) ;
234232 const router = useRouter ( ) ;
235- const openingHours : DailyOpeningHours =
233+ const openingHours =
236234 applicationRound ?. reservationUnitByPk ?. applicationRoundTimeSlots ?? [ ] ;
237235
238236 const { getValues, setValue, watch, handleSubmit } =
@@ -259,7 +257,7 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
259257 // TODO: day is incorrect (empty days at the start are missing, and 200 / 300 priority on the same day gets split into two days)
260258 // TODO refactor the Cell -> ApplicationEventSchedule conversion to use FormTypes
261259 selectedAppEvents . forEach ( ( appEventSchedule , i ) => {
262- const val = appEventSchedule . map ( ( appEvent : ApplicationEvent ) => {
260+ const val = appEventSchedule . map ( ( appEvent ) => {
263261 const { day } = appEvent ;
264262 // debug check
265263 if ( day == null || day < 0 || day > 6 ) {
@@ -318,7 +316,14 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
318316 const selectedAppEvents = selectorData
319317 . map ( ( cell ) => cellsToApplicationEventSchedules ( cell ) )
320318 . map ( ( aes ) =>
321- aes . filter ( ( ae ) => ae . priority === 300 || ae . priority === 200 )
319+ aes
320+ . filter ( ( ae ) => ae . priority === 300 || ae . priority === 200 )
321+ . map ( ( ae ) => {
322+ return {
323+ ...ae ,
324+ priority : ae . priority === 300 ? ( 300 as const ) : ( 200 as const ) ,
325+ } ;
326+ } )
322327 )
323328 . flat ( ) ;
324329 if ( selectedAppEvents . length === 0 ) {
0 commit comments