@@ -11,6 +11,7 @@ import { env } from "@/env";
1111import { notify } from "@/lib/notifications" ;
1212import { api } from "@/trpc/react" ;
1313import { ViewMode } from "@/types/types" ;
14+ import { validateStringLength , validateTimeRange } from "@/types/validation" ;
1415import TableView from "../agencypage/table-view" ;
1516import CalendarView from "../calendar-view" ;
1617import styles from "./agency-interactive-area.module.scss" ;
@@ -75,21 +76,24 @@ export const BookingInteractiveArea = ({
7576 } ,
7677
7778 validate : {
78- title : ( value ) => ( value . trim ( ) . length > 0 ? null : "Title is required" ) ,
79- residentName : ( value ) =>
80- value . trim ( ) . length > 0 ? null : "Resident name is required" ,
81- contactInfo : ( value ) =>
82- value . trim ( ) . length > 0 ? null : "Contact info is required" ,
83- startTime : ( value ) =>
84- value . trim ( ) . length > 0 ? null : "Date and time is required" ,
85- endTime : ( value ) =>
86- value . trim ( ) . length > 0 ? null : "Date and time is required" ,
87- purpose : ( value ) =>
88- value . trim ( ) . length > 0 ? null : "Purpose is required" ,
89- pickupAddress : ( value ) =>
90- value . trim ( ) . length > 0 ? null : "Pickup address is required" ,
91- destinationAddress : ( value ) =>
92- value . trim ( ) . length > 0 ? null : "Destination address is required" ,
79+ title : ( value ) => validateStringLength ( value , 1 , 150 , "Booking name" ) ,
80+ residentName : ( value ) => validateStringLength ( value , 1 , 100 , "Resident name" ) ,
81+ contactInfo : ( value ) => validateStringLength ( value , 1 , 150 , "Contact information" ) ,
82+ additionalInfo : ( value ) => {
83+ // Optional field, only validate max length if provided
84+ if ( value . trim ( ) . length === 0 ) return null ;
85+ return validateStringLength ( value , 0 , 500 , "Additional information" ) ;
86+ } ,
87+ startTime : ( value ) => ( value . trim ( ) . length > 0 ? null : "Date and time is required" ) ,
88+ endTime : ( value , values ) => {
89+ // First check if required
90+ if ( value . trim ( ) . length === 0 ) return "Date and time is required" ;
91+ // Then validate time range
92+ return validateTimeRange ( values . startTime , value ) ;
93+ } ,
94+ purpose : ( value ) => validateStringLength ( value , 1 , 500 , "Purpose of transport" ) ,
95+ pickupAddress : ( value ) => validateStringLength ( value , 1 , 300 , "Pickup address" ) ,
96+ destinationAddress : ( value ) => validateStringLength ( value , 1 , 300 , "Destination address" ) ,
9397 } ,
9498 } ) ;
9599
0 commit comments