feat: add block to ARB rate when trying multiroom booking
This commit is contained in:
committed by
Simon.Emanuelsson
parent
01e160db41
commit
3e0f503314
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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]*$)/,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user