diff --git a/components/Forms/BookingWidget/schema.ts b/components/Forms/BookingWidget/schema.ts index bc0be8d9c..9541abd42 100644 --- a/components/Forms/BookingWidget/schema.ts +++ b/components/Forms/BookingWidget/schema.ts @@ -2,6 +2,18 @@ import { z } from "zod" import type { Location } from "@/types/trpc/routers/hotel/locations" +export const guestRoomsSchema = z.array( + z.object({ + adults: z.number().default(1), + children: z.array( + z.object({ + age: z.number().nonnegative(), + bed: z.number(), + }) + ), + }) +) + export const bookingWidgetSchema = z.object({ bookingCode: z.string(), // Update this as required when working with booking codes component date: z.object({ @@ -25,17 +37,7 @@ export const bookingWidgetSchema = z.object({ { message: "Required" } ), redemption: z.boolean().default(false), - rooms: z.array( - z.object({ - adults: z.number().default(1), - children: z.array( - z.object({ - age: z.number(), - bed: z.number(), - }) - ), - }) - ), + rooms: guestRoomsSchema, search: z.string({ coerce: true }).min(1, "Required"), voucher: z.boolean().default(false), }) diff --git a/components/GuestsRoomsPicker/GuestsRoomPicker/ChildSelector/ChildInfoSelector.tsx b/components/GuestsRoomsPicker/GuestsRoomPicker/ChildSelector/ChildInfoSelector.tsx index 7dbc6d303..d0ff98aba 100644 --- a/components/GuestsRoomsPicker/GuestsRoomPicker/ChildSelector/ChildInfoSelector.tsx +++ b/components/GuestsRoomsPicker/GuestsRoomPicker/ChildSelector/ChildInfoSelector.tsx @@ -12,6 +12,7 @@ type ChildSelectorProps = { index: number availableBedTypes?: ChildBed[] updateChild: (child: Child, index: number) => void + childAgeError: boolean } export default function ChildInfoSelector({ @@ -23,6 +24,7 @@ export default function ChildInfoSelector({ { label: "In extra bed", value: 2 }, ], updateChild = (child: Child, index: number) => {}, + childAgeError, }: ChildSelectorProps) { const intl = useIntl() const ageLabel = intl.formatMessage({ id: "Age" }) @@ -55,29 +57,38 @@ export default function ChildInfoSelector({ return ( <> - { - handleOnSelect(key, "bed") + handleOnSelect(key, "age") }} - name="bed" + name="age" + placeholder={ageLabel} /> - ) : null} + {childAgeError && child.age < 0 ? ( + Child Age is required + ) : null} + +
+ {child.age !== -1 ? ( +