@@ -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" ;
@@ -66,15 +67,24 @@ export const BookingInteractiveArea = ({ initialViewMode = ViewMode.CALENDAR }:
6667 } ,
6768
6869 validate : {
69- title : ( value ) => ( value . trim ( ) . length > 0 ? null : "Title is required" ) ,
70- residentName : ( value ) => ( value . trim ( ) . length > 0 ? null : "Resident name is required" ) ,
71- contactInfo : ( value ) => ( value . trim ( ) . length > 0 ? null : "Contact info is required" ) ,
70+ title : ( value ) => validateStringLength ( value , 1 , 150 , "Booking name" ) ,
71+ residentName : ( value ) => validateStringLength ( value , 1 , 100 , "Resident name" ) ,
72+ contactInfo : ( value ) => validateStringLength ( value , 1 , 150 , "Contact information" ) ,
73+ additionalInfo : ( value ) => {
74+ // Optional field, only validate max length if provided
75+ if ( value . trim ( ) . length === 0 ) return null ;
76+ return validateStringLength ( value , 0 , 500 , "Additional information" ) ;
77+ } ,
7278 startTime : ( value ) => ( value . trim ( ) . length > 0 ? null : "Date and time is required" ) ,
73- endTime : ( value ) => ( value . trim ( ) . length > 0 ? null : "Date and time is required" ) ,
74- purpose : ( value ) => ( value . trim ( ) . length > 0 ? null : "Purpose is required" ) ,
75- pickupAddress : ( value ) => ( value . trim ( ) . length > 0 ? null : "Pickup address is required" ) ,
76- destinationAddress : ( value ) =>
77- value . trim ( ) . length > 0 ? null : "Destination address is required" ,
79+ endTime : ( value , values ) => {
80+ // First check if required
81+ if ( value . trim ( ) . length === 0 ) return "Date and time is required" ;
82+ // Then validate time range
83+ return validateTimeRange ( values . startTime , value ) ;
84+ } ,
85+ purpose : ( value ) => validateStringLength ( value , 1 , 500 , "Purpose of transport" ) ,
86+ pickupAddress : ( value ) => validateStringLength ( value , 1 , 300 , "Pickup address" ) ,
87+ destinationAddress : ( value ) => validateStringLength ( value , 1 , 300 , "Destination address" ) ,
7888 } ,
7989 } ) ;
8090
0 commit comments