@@ -24,6 +24,7 @@ import {
2424 checkTimeStringFormat ,
2525} from "common/src/schemas/schemaCommon" ;
2626import { constructApiDate } from "@/helpers" ;
27+ import { intervalToNumber } from "@/schemas/utils" ;
2728
2829export const PaymentTypes = [ "ONLINE" , "INVOICE" , "ON_SITE" ] as const ;
2930
@@ -442,6 +443,61 @@ export const ReservationUnitEditSchema = z
442443 validateSeasonalTimes ( v . seasons , ctx ) ;
443444 }
444445
446+ // Drafts require this validation
447+ if ( v . minReservationDuration != null && v . maxReservationDuration != null ) {
448+ if ( v . minReservationDuration > v . maxReservationDuration ) {
449+ ctx . addIssue ( {
450+ code : z . ZodIssueCode . custom ,
451+ message : "Min reservation duration must be less than max duration" ,
452+ path : [ "maxReservationDuration" ] ,
453+ } ) ;
454+ }
455+ }
456+
457+ if ( v . minReservationDuration != null ) {
458+ const minDurationMinutes = Math . floor ( v . minReservationDuration / 60 ) ;
459+ if ( minDurationMinutes < intervalToNumber ( v . reservationStartInterval ) ) {
460+ ctx . addIssue ( {
461+ code : z . ZodIssueCode . custom ,
462+ message : "duration can't be less than reservation start interval" ,
463+ path : [ "minReservationDuration" ] ,
464+ } ) ;
465+ }
466+ if (
467+ minDurationMinutes % intervalToNumber ( v . reservationStartInterval ) !==
468+ 0
469+ ) {
470+ ctx . addIssue ( {
471+ code : z . ZodIssueCode . custom ,
472+ message :
473+ "duration must be a multiple of the reservation start interval" ,
474+ path : [ "minReservationDuration" ] ,
475+ } ) ;
476+ }
477+ }
478+
479+ if ( v . maxReservationDuration != null ) {
480+ const maxDurationMinutes = Math . floor ( v . maxReservationDuration / 60 ) ;
481+ if (
482+ maxDurationMinutes % intervalToNumber ( v . reservationStartInterval ) !==
483+ 0
484+ ) {
485+ ctx . addIssue ( {
486+ code : z . ZodIssueCode . custom ,
487+ message :
488+ "duration must be a multiple of the reservation start interval" ,
489+ path : [ "maxReservationDuration" ] ,
490+ } ) ;
491+ }
492+ if ( maxDurationMinutes < intervalToNumber ( v . reservationStartInterval ) ) {
493+ ctx . addIssue ( {
494+ code : z . ZodIssueCode . custom ,
495+ message : "duration can't be less than reservation start interval" ,
496+ path : [ "maxReservationDuration" ] ,
497+ } ) ;
498+ }
499+ }
500+
445501 if ( v . isDraft ) {
446502 return ;
447503 }
@@ -498,16 +554,6 @@ export const ReservationUnitEditSchema = z
498554 }
499555 }
500556
501- if ( v . minReservationDuration != null && v . maxReservationDuration != null ) {
502- if ( v . minReservationDuration > v . maxReservationDuration ) {
503- ctx . addIssue ( {
504- code : z . ZodIssueCode . custom ,
505- message : "Min reservation duration must be less than max duration" ,
506- path : [ "maxReservationDuration" ] ,
507- } ) ;
508- }
509- }
510-
511557 if ( v . hasScheduledPublish ) {
512558 validateDateTimeInterval ( {
513559 beginDate : v . hasPublishBegins ? v . publishBeginsDate : "" ,
0 commit comments