diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx index eea068c1c..f470875f9 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx @@ -2,7 +2,7 @@ import stringify from "json-stable-stringify-without-jsonify" import { notFound } from "next/navigation" import { Suspense } from "react" -import { REDEMPTION } from "@/constants/booking" +import { combineRegExps, rateTypeRegex, REDEMPTION } from "@/constants/booking" import SelectRate from "@/components/HotelReservation/SelectRate" import { HotelInfoCardSkeleton } from "@/components/HotelReservation/SelectRate/HotelInfoCard" @@ -12,6 +12,11 @@ import { convertSearchParamsToObj } from "@/utils/url" import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" import type { LangParams, PageArgs } from "@/types/params" +const singleRoomRateTypes = combineRegExps( + [rateTypeRegex.ARB, rateTypeRegex.VOUCHER], + "i" +) + export default async function SelectRatePage({ params, searchParams, @@ -21,11 +26,11 @@ export default async function SelectRatePage({ const isMultiRoom = booking.rooms.length > 1 const isRedemption = booking.searchType === REDEMPTION - const isVoucher = booking.bookingCode - ? /(^VO[0-9a-z]*$)/i.test(booking.bookingCode) + const isArbOrVoucher = booking.bookingCode + ? singleRoomRateTypes.test(booking.bookingCode) : false - if ((isMultiRoom && isRedemption) || (isMultiRoom && isVoucher)) { + if ((isMultiRoom && isRedemption) || (isMultiRoom && isArbOrVoucher)) { return notFound() } diff --git a/apps/scandic-web/constants/booking.tsx b/apps/scandic-web/constants/booking.tsx index 54a821b3b..f08b96ed8 100644 --- a/apps/scandic-web/constants/booking.tsx +++ b/apps/scandic-web/constants/booking.tsx @@ -170,3 +170,12 @@ export enum PaymentCallbackStatusEnum { Error = "error", Cancel = "cancel", } + +export function combineRegExps(regexps: RegExp[], flags = "") { + return new RegExp(regexps.map((r) => r.source).join("|"), flags) +} + +export const rateTypeRegex = { + ARB: /(^B[a-z]{3}\d{6}$)/, + VOUCHER: /(^VO[0-9a-z]*$)/, +}