Files
web/packages/booking-flow/lib/components/BookingFlowInput/errors.ts
Anton Gunnarsson 6ee262ad89 Merged in chore/booking-flow-cleaning (pull request #3354)
chore: Clean booking-flow

* Clean booking-flow

* Fix type issue


Approved-by: Joakim Jäderberg
Approved-by: Linus Flood
2025-12-17 13:04:26 +00:00

188 lines
6.6 KiB
TypeScript

import { logger } from "@scandic-hotels/common/logger"
import { phoneErrors } from "@scandic-hotels/common/utils/zod/phoneValidator"
import { bookingWidgetErrors } from "../BookingWidget/BookingWidgetForm/schema"
import {
multiroomErrors,
roomOneErrors,
} from "../EnterDetails/enterDetailsErrors"
import type { IntlShape } from "react-intl"
import type { BookingFlowVariant } from "../../bookingFlowConfig/bookingFlowVariants"
export function getErrorMessage(
intl: IntlShape,
variant: BookingFlowVariant,
errorCode?: string
) {
switch (errorCode) {
case bookingWidgetErrors.BOOKING_CODE_INVALID:
return intl.formatMessage({
id: "error.bookingCodeInvalid",
defaultMessage: "Booking code is invalid",
})
case bookingWidgetErrors.AGE_REQUIRED:
return intl.formatMessage({
id: "error.ageRequired",
defaultMessage: "Age is required",
})
case bookingWidgetErrors.BED_CHOICE_REQUIRED:
return intl.formatMessage({
id: "error.bedChoiceRequired",
defaultMessage: "Bed choice is required",
})
case bookingWidgetErrors.CHILDREN_EXCEEDS_ADULTS:
return intl.formatMessage({
id: "error.childrenExceedsAdults",
defaultMessage:
"You cannot have more children in adults bed than adults in the room",
})
case bookingWidgetErrors.REQUIRED:
return intl.formatMessage({
id: "error.required",
defaultMessage: "Required",
})
case bookingWidgetErrors.DESTINATION_REQUIRED:
return intl.formatMessage({
id: "error.destinationRequired",
defaultMessage: "Destination required",
})
case bookingWidgetErrors.MULTIROOM_BOOKING_CODE_UNAVAILABLE:
return intl.formatMessage({
id: "error.multiroomBookingCodeUnavailable",
defaultMessage:
"Multi-room booking is not available with this booking code.",
})
case bookingWidgetErrors.MULTIROOM_REWARD_NIGHT_UNAVAILABLE:
switch (variant) {
case "scandic":
return intl.formatMessage({
id: "error.multiroomRewardNightUnavailable",
defaultMessage:
"Multi-room booking is not available with reward night.",
})
case "partner-sas":
return intl.formatMessage({
id: "partnerSas.error.multiroomRewardNightUnavailable",
defaultMessage:
"Multi-room bookings are not available with EuroBonus points.",
})
default:
const _exhaustiveCheck: never = variant
throw new Error(`Unknown variant: ${variant}`)
}
case bookingWidgetErrors.CODE_VOUCHER_REWARD_NIGHT_UNAVAILABLE:
return intl.formatMessage({
id: "error.codeVoucherRewardNightUnavailable",
defaultMessage:
"Reward nights can't be combined with codes or vouchers.",
})
case phoneErrors.PHONE_NUMBER_TOO_SHORT:
return intl.formatMessage({
id: "error.phoneNumberTooShort",
defaultMessage: "The number you have entered is too short",
})
case multiroomErrors.FIRST_NAME_REQUIRED:
case roomOneErrors.FIRST_NAME_REQUIRED:
return intl.formatMessage({
id: "error.firstNameRequired",
defaultMessage: "First name is required",
})
case multiroomErrors.FIRST_NAME_SPECIAL_CHARACTERS:
case roomOneErrors.FIRST_NAME_SPECIAL_CHARACTERS:
return intl.formatMessage({
id: "error.firstNameSpecialCharacters",
defaultMessage: "First name can't contain any special characters",
})
case multiroomErrors.LAST_NAME_REQUIRED:
case roomOneErrors.LAST_NAME_REQUIRED:
return intl.formatMessage({
id: "error.lastNameRequired",
defaultMessage: "Last name is required",
})
case multiroomErrors.LAST_NAME_SPECIAL_CHARACTERS:
case roomOneErrors.LAST_NAME_SPECIAL_CHARACTERS:
return intl.formatMessage({
id: "error.lastNameSpecialCharacters",
defaultMessage: "Last name can't contain any special characters",
})
case multiroomErrors.FIRST_AND_LAST_NAME_UNIQUE:
return intl.formatMessage({
id: "error.firstAndLastNameUnique",
defaultMessage:
"First and last name can't be the same in two different rooms",
})
case multiroomErrors.EMAIL_REQUIRED:
case roomOneErrors.EMAIL_REQUIRED:
return intl.formatMessage({
id: "error.emailRequired",
defaultMessage: "Email address is required",
})
case multiroomErrors.COUNTRY_REQUIRED:
case roomOneErrors.COUNTRY_REQUIRED:
return intl.formatMessage({
id: "error.countryRequired",
defaultMessage: "Country is required",
})
case multiroomErrors.PHONE_REQUIRED:
case roomOneErrors.PHONE_REQUIRED:
return intl.formatMessage({
id: "error.phoneRequired",
defaultMessage: "Phone is required",
})
case multiroomErrors.PHONE_REQUESTED:
case roomOneErrors.PHONE_REQUESTED:
return intl.formatMessage({
id: "error.phoneRequested",
defaultMessage: "Please enter a valid phone number",
})
case roomOneErrors.BIRTH_DATE_REQUIRED:
return intl.formatMessage({
id: "error.birthDateRequired",
defaultMessage: "Date of birth is required",
})
case roomOneErrors.BIRTH_DATE_AGE_18:
return intl.formatMessage({
id: "error.atleast18YearsOld",
defaultMessage: "Must be at least 18 years of age to continue",
})
case roomOneErrors.ZIP_CODE_INVALID:
return intl.formatMessage({
id: "error.zipCodeInvalid",
defaultMessage: "The postal code can only contain numbers and letters",
})
case roomOneErrors.ZIP_CODE_REQUIRED:
return intl.formatMessage({
id: "error.zipCodeRequired",
defaultMessage: "Zip code is required",
})
case multiroomErrors.MEMBERSHIP_NO_ONLY_DIGITS:
case roomOneErrors.MEMBERSHIP_NO_ONLY_DIGITS:
return intl.formatMessage({
id: "error.membershipNoOnlyDigits",
defaultMessage: "Only digits are allowed",
})
case multiroomErrors.MEMBERSHIP_NO_INVALID:
case roomOneErrors.MEMBERSHIP_NO_INVALID:
return intl.formatMessage({
id: "error.membershipNoInvalid",
defaultMessage: "Invalid membership number format",
})
case multiroomErrors.MEMBERSHIP_NO_UNIQUE:
return intl.formatMessage({
id: "error.membershipNotUniqueForMultipleRooms",
defaultMessage:
"Membership number can't be the same for two different rooms",
})
case undefined:
case null:
case "":
return errorCode
default:
logger.warn("Error code not supported:", errorCode)
return errorCode
}
}