feat: SW-1422 Enabled booking code in booking widget
This commit is contained in:
@@ -35,9 +35,30 @@ export const guestRoomSchema = z
|
||||
|
||||
export const guestRoomsSchema = z.array(guestRoomSchema)
|
||||
|
||||
export const bookingCodeSchema = z
|
||||
.object({
|
||||
value: z.string().refine(
|
||||
(value) => {
|
||||
if (
|
||||
!value ||
|
||||
/(^D\d*$)|(^DSH[0-9a-z]*$)|(^L\d*$)|(^LH[0-9a-z]*$)|(^B[a-z]{3}\d{6})|(^VO[0-9a-z]*$)|^[0-9a-z]*$/i.test(
|
||||
value
|
||||
)
|
||||
) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
{ message: "Invalid booking code" }
|
||||
),
|
||||
remember: z.boolean(),
|
||||
})
|
||||
.optional()
|
||||
|
||||
export const bookingWidgetSchema = z
|
||||
.object({
|
||||
bookingCode: z.string(), // Update this as required when working with booking codes component
|
||||
bookingCode: bookingCodeSchema,
|
||||
date: z.object({
|
||||
// Update this as required once started working with Date picker in Nights component
|
||||
fromDate: z.string(),
|
||||
@@ -70,7 +91,27 @@ export const bookingWidgetSchema = z
|
||||
hotel: z.number().optional(),
|
||||
city: z.string().optional(),
|
||||
})
|
||||
.refine((value) => value.hotel || value.city, {
|
||||
message: "Destination required",
|
||||
path: ["search"],
|
||||
.superRefine((value, ctx) => {
|
||||
if (!value.hotel && !value.city) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Destination required",
|
||||
path: ["search"],
|
||||
})
|
||||
}
|
||||
if (
|
||||
value.rooms.length > 1 &&
|
||||
value.bookingCode?.value.toLowerCase().startsWith("vo")
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Multiroom with voucher error",
|
||||
path: ["bookingCode.value"],
|
||||
})
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Multiroom with voucher error",
|
||||
path: ["rooms"],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user