@@ -468,7 +468,7 @@ const ReservationUnit = ({
468468 searchUIDate != null && isValidDate ( searchUIDate )
469469 ? searchDate ?? ""
470470 : defaultDateString ,
471- duration : searchDuration ?? minReservationDurationMinutes ,
471+ duration : Math . max ( searchDuration ?? 0 , minReservationDurationMinutes ) ,
472472 time : searchTime ?? getTimeString ( defaultDate ) ,
473473 } ;
474474
@@ -519,16 +519,18 @@ const ReservationUnit = ({
519519 const [ hours , minutes ] = timeValue . split ( ":" ) . map ( Number ) ;
520520 start . setHours ( hours , minutes , 0 , 0 ) ;
521521 const end = addMinutes ( start , durationValue ) ;
522+ const isReservable = isReservationReservable ( {
523+ reservationUnit,
524+ activeApplicationRounds,
525+ start,
526+ end,
527+ skipLengthCheck : false ,
528+ } ) ;
529+
522530 return {
523531 start,
524532 end,
525- isReservable : isReservationReservable ( {
526- reservationUnit,
527- activeApplicationRounds,
528- start,
529- end,
530- skipLengthCheck : false ,
531- } ) ,
533+ isReservable,
532534 durationMinutes : durationValue ,
533535 } ;
534536 } , [
@@ -639,23 +641,28 @@ const ReservationUnit = ({
639641 return false ;
640642 }
641643
642- if (
643- ! isReservationReservable ( {
644- reservationUnit,
645- activeApplicationRounds,
646- start,
647- end,
648- skipLengthCheck : false ,
649- } )
650- ) {
644+ // the next check is going to systematically fail unless the times are at least minReservationDuration apart
645+ const { minReservationDuration } = reservationUnit ;
646+ const minEnd = addSeconds ( start , minReservationDuration ?? 0 ) ;
647+ const newEnd = new Date ( Math . max ( end . getTime ( ) , minEnd . getTime ( ) ) ) ;
648+
649+ const isReservable = isReservationReservable ( {
650+ reservationUnit,
651+ activeApplicationRounds,
652+ start,
653+ end : newEnd ,
654+ skipLengthCheck : false ,
655+ } ) ;
656+
657+ if ( ! isReservable ) {
651658 return false ;
652659 }
653660
654661 // Limit the duration to the max reservation duration
655662 // TODO should be replaced with a utility function that is properly named
656663 const newReservation = getNewReservation ( {
657664 start,
658- end,
665+ end : newEnd ,
659666 reservationUnit,
660667 } ) ;
661668
@@ -698,15 +705,14 @@ const ReservationUnit = ({
698705 ? addSeconds ( start , reservationUnit ?. minReservationDuration ?? 0 )
699706 : new Date ( end ) ;
700707
701- if (
702- ! isReservationReservable ( {
703- reservationUnit,
704- activeApplicationRounds,
705- start,
706- end : normalizedEnd ,
707- skipLengthCheck : false ,
708- } )
709- ) {
708+ const isReservable = isReservationReservable ( {
709+ reservationUnit,
710+ activeApplicationRounds,
711+ start,
712+ end : normalizedEnd ,
713+ skipLengthCheck : false ,
714+ } ) ;
715+ if ( ! isReservable ) {
710716 return false ;
711717 }
712718
@@ -749,16 +755,17 @@ const ReservationUnit = ({
749755 end : focusSlot ?. end ,
750756 state : "INITIAL" ,
751757 } ;
758+ const isReservable = isReservationReservable ( {
759+ reservationUnit,
760+ activeApplicationRounds,
761+ start : focusSlot ?. start ,
762+ end : focusSlot ?. end ,
763+ skipLengthCheck : false ,
764+ } ) ;
765+
752766 const shouldDisplayFocusSlot =
753- focusSlot ?. start != null &&
754- focusSlot ?. end != null &&
755- isReservationReservable ( {
756- reservationUnit,
757- activeApplicationRounds,
758- start : focusSlot ?. start ,
759- end : focusSlot ?. end ,
760- skipLengthCheck : false ,
761- } ) ;
767+ focusSlot ?. start != null && focusSlot ?. end != null && isReservable ;
768+
762769 return [
763770 ...existingReservations ,
764771 ...( shouldDisplayFocusSlot ? [ focusEvent ] : [ ] ) ,
0 commit comments