fix(SW-2385): add booking widget error messages
This commit is contained in:
committed by
Michael Zetterberg
parent
595eb575d7
commit
e544feaa36
@@ -4,14 +4,27 @@ import { REDEMPTION } from "@/constants/booking"
|
|||||||
|
|
||||||
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||||
|
|
||||||
|
export const bookingWidgetErrors = {
|
||||||
|
AGE_REQUIRED: "AGE_REQUIRED",
|
||||||
|
BED_CHOICE_REQUIRED: "BED_CHOICE_REQUIRED",
|
||||||
|
CHILDREN_EXCEEDS_ADULTS: "CHILDREN_EXCEEDS_ADULTS",
|
||||||
|
BOOKING_CODE_INVALID: "BOOKING_CODE_INVALID",
|
||||||
|
REQUIRED: "REQUIRED",
|
||||||
|
DESTINATION_REQUIRED: "DESTINATION_REQUIRED",
|
||||||
|
MULTIROOM_BOOKING_CODE_UNAVAILABLE: "MULTIROOM_BOOKING_CODE_UNAVAILABLE",
|
||||||
|
MULTIROOM_REWARD_NIGHT_UNAVAILABLE: "MULTIROOM_REWARD_NIGHT_UNAVAILABLE",
|
||||||
|
CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE:
|
||||||
|
"CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE",
|
||||||
|
} as const
|
||||||
|
|
||||||
export const guestRoomSchema = z
|
export const guestRoomSchema = z
|
||||||
.object({
|
.object({
|
||||||
adults: z.number().default(1),
|
adults: z.number().default(1),
|
||||||
childrenInRoom: z
|
childrenInRoom: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
age: z.number().min(0, "Age is required"),
|
age: z.number().min(0, bookingWidgetErrors.AGE_REQUIRED),
|
||||||
bed: z.number().min(0, "Bed choice is required"),
|
bed: z.number().min(0, bookingWidgetErrors.BED_CHOICE_REQUIRED),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.default([]),
|
.default([]),
|
||||||
@@ -27,8 +40,7 @@ export const guestRoomSchema = z
|
|||||||
|
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message:
|
message: bookingWidgetErrors.CHILDREN_EXCEEDS_ADULTS,
|
||||||
"You cannot have more children in adults bed than adults in the room",
|
|
||||||
path: ["childrenInRoom", lastAdultBedIndex],
|
path: ["childrenInRoom", lastAdultBedIndex],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -41,19 +53,12 @@ export const bookingCodeSchema = z
|
|||||||
value: z
|
value: z
|
||||||
.string()
|
.string()
|
||||||
.refine(
|
.refine(
|
||||||
(value) => {
|
(value) =>
|
||||||
if (
|
|
||||||
!value ||
|
!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(
|
/(^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
|
value
|
||||||
)
|
),
|
||||||
) {
|
{ message: bookingWidgetErrors.BOOKING_CODE_INVALID }
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ message: "Invalid booking code" }
|
|
||||||
)
|
)
|
||||||
.default(""),
|
.default(""),
|
||||||
remember: z.boolean().default(false),
|
remember: z.boolean().default(false),
|
||||||
@@ -71,7 +76,7 @@ export const bookingWidgetSchema = z
|
|||||||
}),
|
}),
|
||||||
redemption: z.boolean().default(false),
|
redemption: z.boolean().default(false),
|
||||||
rooms: guestRoomsSchema,
|
rooms: guestRoomsSchema,
|
||||||
search: z.string({ coerce: true }).min(1, "Required"),
|
search: z.string({ coerce: true }).min(1, bookingWidgetErrors.REQUIRED),
|
||||||
selectedSearch: z.string().optional(),
|
selectedSearch: z.string().optional(),
|
||||||
hotel: z.number().optional(),
|
hotel: z.number().optional(),
|
||||||
city: z.string().optional(),
|
city: z.string().optional(),
|
||||||
@@ -80,43 +85,43 @@ export const bookingWidgetSchema = z
|
|||||||
if (!value.hotel && !value.city) {
|
if (!value.hotel && !value.city) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Destination required",
|
message: bookingWidgetErrors.DESTINATION_REQUIRED,
|
||||||
path: ["search"],
|
path: ["search"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (value.rooms.length > 1 && value.bookingCode?.value.startsWith("VO")) {
|
if (value.rooms.length > 1 && value.bookingCode?.value.startsWith("VO")) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Multi-room booking is not available with this booking code.",
|
message: bookingWidgetErrors.MULTIROOM_BOOKING_CODE_UNAVAILABLE,
|
||||||
path: ["bookingCode.value"],
|
path: ["bookingCode.value"],
|
||||||
})
|
})
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Multi-room booking is not available with this booking code.",
|
message: bookingWidgetErrors.MULTIROOM_BOOKING_CODE_UNAVAILABLE,
|
||||||
path: ["rooms"],
|
path: ["rooms"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (value.rooms.length > 1 && value.redemption) {
|
if (value.rooms.length > 1 && value.redemption) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Multi-room booking is not available with reward night.",
|
message: bookingWidgetErrors.MULTIROOM_REWARD_NIGHT_UNAVAILABLE,
|
||||||
path: [REDEMPTION],
|
path: [REDEMPTION],
|
||||||
})
|
})
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Multi-room booking is not available with reward night.",
|
message: bookingWidgetErrors.MULTIROOM_REWARD_NIGHT_UNAVAILABLE,
|
||||||
path: ["rooms"],
|
path: ["rooms"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (value.bookingCode?.value && value.redemption) {
|
if (value.bookingCode?.value && value.redemption) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Code and voucher is not available with reward night.",
|
message: bookingWidgetErrors.CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE,
|
||||||
path: [REDEMPTION],
|
path: [REDEMPTION],
|
||||||
})
|
})
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "Code and voucher is not available with reward night.",
|
message: bookingWidgetErrors.CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE,
|
||||||
path: ["bookingCode.value"],
|
path: ["bookingCode.value"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { bookingWidgetErrors } from "@/components/Forms/BookingWidget/schema"
|
||||||
import { editProfileErrors } from "@/components/Forms/Edit/Profile/schema"
|
import { editProfileErrors } from "@/components/Forms/Edit/Profile/schema"
|
||||||
import { signupErrors } from "@/components/Forms/Signup/schema"
|
import { signupErrors } from "@/components/Forms/Signup/schema"
|
||||||
import { multiroomErrors } from "@/components/HotelReservation/EnterDetails/Details/Multiroom/schema"
|
import { multiroomErrors } from "@/components/HotelReservation/EnterDetails/Details/Multiroom/schema"
|
||||||
@@ -16,6 +17,10 @@ export function getErrorMessage(intl: IntlShape, errorCode?: string) {
|
|||||||
return intl.formatMessage({
|
return intl.formatMessage({
|
||||||
defaultMessage: "Invalid booking number",
|
defaultMessage: "Invalid booking number",
|
||||||
})
|
})
|
||||||
|
case bookingWidgetErrors.BOOKING_CODE_INVALID:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Booking code is invalid",
|
||||||
|
})
|
||||||
case findMyBookingErrors.FIRST_NAME_REQUIRED:
|
case findMyBookingErrors.FIRST_NAME_REQUIRED:
|
||||||
case signupErrors.FIRST_NAME_REQUIRED:
|
case signupErrors.FIRST_NAME_REQUIRED:
|
||||||
case multiroomErrors.FIRST_NAME_REQUIRED:
|
case multiroomErrors.FIRST_NAME_REQUIRED:
|
||||||
@@ -115,6 +120,41 @@ export function getErrorMessage(intl: IntlShape, errorCode?: string) {
|
|||||||
return intl.formatMessage({
|
return intl.formatMessage({
|
||||||
defaultMessage: "Invalid membership number format",
|
defaultMessage: "Invalid membership number format",
|
||||||
})
|
})
|
||||||
|
case bookingWidgetErrors.AGE_REQUIRED:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Age is required",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.BED_CHOICE_REQUIRED:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Bed choice is required",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.CHILDREN_EXCEEDS_ADULTS:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage:
|
||||||
|
"You cannot have more children in adults bed than adults in the room",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.REQUIRED:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Required",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.DESTINATION_REQUIRED:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Destination required",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.MULTIROOM_BOOKING_CODE_UNAVAILABLE:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage:
|
||||||
|
"Multi-room booking is not available with this booking code.",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.MULTIROOM_REWARD_NIGHT_UNAVAILABLE:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage:
|
||||||
|
"Multi-room booking is not available with reward night.",
|
||||||
|
})
|
||||||
|
case bookingWidgetErrors.CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE:
|
||||||
|
return intl.formatMessage({
|
||||||
|
defaultMessage: "Code and voucher is not available with reward night.",
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
console.warn("Error code not supported:", errorCode)
|
console.warn("Error code not supported:", errorCode)
|
||||||
return errorCode
|
return errorCode
|
||||||
|
|||||||
Reference in New Issue
Block a user