Files
web/apps/scandic-web/utils/getErrorMessage.ts
Bianca Widstam 46fa42750f Merged in feat/BOOK-529-update-GLA-design-mystay (pull request #3230)
Feat/BOOK-529 update GLA design mystay

* feat(BOOK-529): update gla design on my stay

* feat(BOOK-529): open gla modal if error

* feat(BOOK-529): add inline accordion to storybook

* feat(529): move errormessage below message

* feat(529): update infomodal

* feat(BOOK-529): update infomodal

* feat(BOOK-529): hide guarantee info for adding ancillaries if prepaid

* feat(BOOK-529): update width on info dialog

* feat(BOOK-529): fix alignment

* feat(BOOK-529): check if member price

* feat(BOOK-529): refactor msg

* feat(BOOK-529): refactor terms and conditions to own component

* feat(BOOK-529): clean up confirmation step


Approved-by: Christel Westerberg
2025-11-28 14:27:25 +00:00

199 lines
7.6 KiB
TypeScript

import {
multiroomErrors,
roomOneErrors,
} from "@scandic-hotels/booking-flow/components/EnterDetails/enterDetailsErrors"
import { logger } from "@scandic-hotels/common/logger"
import { phoneErrors } from "@scandic-hotels/common/utils/zod/phoneValidator"
import { signupErrors } from "@scandic-hotels/trpc/routers/user/schemas"
import { editProfileErrors } from "@/components/Forms/Edit/Profile/schema"
import { findMyBookingErrors } from "@/components/HotelReservation/FindMyBooking/schema"
import { ancillaryError } from "@/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema"
import { paymentError } from "@/components/HotelReservation/MyStay/ReferenceCard/Actions/Upcoming/ManageStay/Actions/GuaranteeLateArrival/Form/schema"
import type { IntlShape } from "react-intl"
import { editGuestDetailsErrors } from "@/types/components/hotelReservation/myStay/modifyContact"
export function getErrorMessage(intl: IntlShape, errorCode?: string) {
switch (errorCode) {
case ancillaryError.MIN_QUANTITY_NOT_REACHED:
return intl.formatMessage({
id: "addAncillary.selectQuantityStep.minQuantityNotReached",
defaultMessage: "You must select at least one quantity",
})
case ancillaryError.TERMS_NOT_ACCEPTED:
case paymentError.TERMS_REQUIRED:
return intl.formatMessage({
id: "common.mustAcceptTermsError",
defaultMessage: "You must accept the terms and conditions",
})
case findMyBookingErrors.BOOKING_NUMBER_INVALID:
return intl.formatMessage({
id: "error.invalidBookingNumber",
defaultMessage: "Invalid booking number",
})
case findMyBookingErrors.BOOKING_NUMBER_REQUIRED:
return intl.formatMessage({
id: "error.invalidBookingNumber",
defaultMessage: "Invalid booking number",
})
case findMyBookingErrors.FIRST_NAME_REQUIRED:
case signupErrors.FIRST_NAME_REQUIRED:
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 findMyBookingErrors.LAST_NAME_REQUIRED:
case signupErrors.LAST_NAME_REQUIRED:
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 findMyBookingErrors.EMAIL_REQUIRED:
case multiroomErrors.EMAIL_REQUIRED:
case roomOneErrors.EMAIL_REQUIRED:
case signupErrors.EMAIL_REQUIRED:
case editGuestDetailsErrors.EMAIL_REQUIRED:
return intl.formatMessage({
id: "error.emailRequired",
defaultMessage: "Email address is required",
})
case signupErrors.EMAIL_INVALID:
case editGuestDetailsErrors.EMAIL_INVALID:
return intl.formatMessage({
id: "error.emailInvalid",
defaultMessage: "Email address is invalid",
})
case signupErrors.COUNTRY_REQUIRED:
case multiroomErrors.COUNTRY_REQUIRED:
case roomOneErrors.COUNTRY_REQUIRED:
case editProfileErrors.COUNTRY_REQUIRED:
return intl.formatMessage({
id: "error.countryRequired",
defaultMessage: "Country is required",
})
case signupErrors.PHONE_REQUIRED:
case multiroomErrors.PHONE_REQUIRED:
case roomOneErrors.PHONE_REQUIRED:
case editProfileErrors.PHONE_REQUIRED:
case editGuestDetailsErrors.PHONE_REQUIRED:
return intl.formatMessage({
id: "error.phoneRequired",
defaultMessage: "Phone is required",
})
case phoneErrors.PHONE_NUMBER_TOO_SHORT:
return intl.formatMessage({
id: "error.phoneNumberTooShort",
defaultMessage: "The number you have entered is too short",
})
case phoneErrors.PHONE_REQUESTED:
case signupErrors.PHONE_REQUESTED:
case multiroomErrors.PHONE_REQUESTED:
case roomOneErrors.PHONE_REQUESTED:
case editProfileErrors.PHONE_REQUESTED:
case editGuestDetailsErrors.PHONE_REQUESTED:
return intl.formatMessage({
id: "error.phoneRequested",
defaultMessage: "Please enter a valid phone number",
})
case signupErrors.BIRTH_DATE_REQUIRED:
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_REQUIRED:
case editProfileErrors.ZIP_CODE_REQUIRED:
case signupErrors.ZIP_CODE_REQUIRED:
return intl.formatMessage({
id: "error.zipCodeRequired",
defaultMessage: "Zip code is required",
})
case roomOneErrors.ZIP_CODE_INVALID:
case editProfileErrors.ZIP_CODE_INVALID:
case signupErrors.ZIP_CODE_INVALID:
return intl.formatMessage({
id: "error.zipCodeInvalid",
defaultMessage: "The postal code can only contain numbers and letters",
})
case signupErrors.PASSWORD_REQUIRED:
return intl.formatMessage({
id: "error.passwordRequired",
defaultMessage: "Password is required",
})
case editProfileErrors.PASSWORD_NEW_REQUIRED:
return intl.formatMessage({
id: "error.passwordNewRequired",
defaultMessage: "New password is required",
})
case editProfileErrors.PASSWORD_RETYPE_NEW_REQUIRED:
return intl.formatMessage({
id: "error.passwordRetypeNewRequired",
defaultMessage: "Confirm your new password",
})
case editProfileErrors.PASSWORD_CURRENT_REQUIRED:
return intl.formatMessage({
id: "error.passwordCurrentRequired",
defaultMessage: "Current password is required",
})
case editProfileErrors.PASSWORD_NEW_NOT_MATCH:
return intl.formatMessage({
id: "error.passwordNewNotMatch",
defaultMessage: "Passwords do not match",
})
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
}
}