fix: filter out available bedtypes
This commit is contained in:
@@ -17,7 +17,7 @@ export default async function SummaryPage({
|
||||
getQueryParamsForEnterDetails(selectRoomParams)
|
||||
|
||||
const availability = await getSelectedRoomAvailability({
|
||||
hotelId: parseInt(hotel),
|
||||
hotelId: hotel,
|
||||
adults,
|
||||
children,
|
||||
roomStayStartDate: fromDate,
|
||||
@@ -35,25 +35,25 @@ export default async function SummaryPage({
|
||||
|
||||
const prices = user
|
||||
? {
|
||||
local: {
|
||||
price: availability.memberRate?.localPrice.pricePerStay,
|
||||
currency: availability.memberRate?.localPrice.currency,
|
||||
},
|
||||
euro: {
|
||||
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
||||
currency: availability.memberRate?.requestedPrice?.currency,
|
||||
},
|
||||
}
|
||||
local: {
|
||||
price: availability.memberRate?.localPrice.pricePerStay,
|
||||
currency: availability.memberRate?.localPrice.currency,
|
||||
},
|
||||
euro: {
|
||||
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
||||
currency: availability.memberRate?.requestedPrice?.currency,
|
||||
},
|
||||
}
|
||||
: {
|
||||
local: {
|
||||
price: availability.publicRate?.localPrice.pricePerStay,
|
||||
currency: availability.publicRate?.localPrice.currency,
|
||||
},
|
||||
euro: {
|
||||
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
||||
currency: availability.publicRate?.requestedPrice?.currency,
|
||||
},
|
||||
}
|
||||
local: {
|
||||
price: availability.publicRate?.localPrice.pricePerStay,
|
||||
currency: availability.publicRate?.localPrice.currency,
|
||||
},
|
||||
euro: {
|
||||
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
||||
currency: availability.publicRate?.requestedPrice?.currency,
|
||||
},
|
||||
}
|
||||
|
||||
return (
|
||||
<Summary
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function StepPage({
|
||||
const breakfastInput = { adults, fromDate, hotelId, toDate }
|
||||
void getBreakfastPackages(breakfastInput)
|
||||
void getSelectedRoomAvailability({
|
||||
hotelId: parseInt(searchParams.hotel),
|
||||
hotelId,
|
||||
adults,
|
||||
children,
|
||||
roomStayStartDate: fromDate,
|
||||
@@ -67,7 +67,7 @@ export default async function StepPage({
|
||||
include: [HotelIncludeEnum.RoomCategories],
|
||||
})
|
||||
const roomAvailability = await getSelectedRoomAvailability({
|
||||
hotelId: parseInt(searchParams.hotel),
|
||||
hotelId,
|
||||
adults,
|
||||
children,
|
||||
roomStayStartDate: fromDate,
|
||||
@@ -98,27 +98,17 @@ export default async function StepPage({
|
||||
id: "Select payment method",
|
||||
})
|
||||
|
||||
const availableRoom = roomAvailability.selectedRoom?.roomType
|
||||
const bedTypes = hotelData.included
|
||||
?.find((room) => room.name === availableRoom)
|
||||
?.roomTypes.map((room) => ({
|
||||
description: room.mainBed.description,
|
||||
size: room.mainBed.widthRange,
|
||||
value: room.code,
|
||||
}))
|
||||
|
||||
return (
|
||||
<section>
|
||||
<HistoryStateManager />
|
||||
|
||||
{/* TODO: How to handle no beds found? */}
|
||||
{bedTypes ? (
|
||||
{roomAvailability.bedTypes ? (
|
||||
<SectionAccordion
|
||||
header="Select bed"
|
||||
step={StepEnum.selectBed}
|
||||
label={intl.formatMessage({ id: "Request bedtype" })}
|
||||
>
|
||||
<BedType bedTypes={bedTypes} />
|
||||
<BedType bedTypes={roomAvailability.bedTypes} />
|
||||
</SectionAccordion>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export const getRoomsAvailabilityInputSchema = z.object({
|
||||
})
|
||||
|
||||
export const getSelectedRoomAvailabilityInputSchema = z.object({
|
||||
hotelId: z.number(),
|
||||
hotelId: z.string(),
|
||||
roomStayStartDate: z.string(),
|
||||
roomStayEndDate: z.string(),
|
||||
adults: z.number(),
|
||||
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
getRoomsAvailabilityInputSchema,
|
||||
getSelectedRoomAvailabilityInputSchema,
|
||||
type HotelDataInput,
|
||||
HotelIncludeEnum,
|
||||
} from "./input"
|
||||
import {
|
||||
breakfastPackagesSchema,
|
||||
@@ -57,6 +58,7 @@ import {
|
||||
} from "./utils"
|
||||
|
||||
import { FacilityCardTypeEnum } from "@/types/components/hotelPage/facilities"
|
||||
import type { BedType } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
import type { RequestOptionsWithOutBody } from "@/types/fetch"
|
||||
@@ -686,6 +688,7 @@ export const hotelQueryRouter = router({
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
language: toApiLang(ctx.lang),
|
||||
}
|
||||
|
||||
selectedRoomAvailabilityCounter.add(1, {
|
||||
@@ -766,10 +769,26 @@ export const hotelQueryRouter = router({
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
const hotelData = await getHotelData(
|
||||
{
|
||||
hotelId,
|
||||
language: ctx.lang,
|
||||
include: [HotelIncludeEnum.RoomCategories],
|
||||
},
|
||||
ctx.serviceToken
|
||||
)
|
||||
|
||||
const selectedRoom = validateAvailabilityData.data.roomConfigurations
|
||||
.filter((room) => room.status === "Available")
|
||||
.find((room) => room.roomTypeCode === roomTypeCode)
|
||||
|
||||
const availableRoomsInCategory =
|
||||
validateAvailabilityData.data.roomConfigurations.filter(
|
||||
(room) =>
|
||||
room.status === "Available" &&
|
||||
room.roomType === selectedRoom?.roomType
|
||||
)
|
||||
|
||||
if (!selectedRoom) {
|
||||
console.error("No matching room found")
|
||||
return null
|
||||
@@ -793,6 +812,24 @@ export const hotelQueryRouter = router({
|
||||
(rate) => rate.rateCode === rateCode
|
||||
)?.cancellationText ?? ""
|
||||
|
||||
const bedTypes = availableRoomsInCategory
|
||||
.map((availRoom) => {
|
||||
const matchingRoom = hotelData?.included
|
||||
?.find((room) => room.name === availRoom.roomType)
|
||||
?.roomTypes.find(
|
||||
(roomType) => roomType.code === availRoom.roomTypeCode
|
||||
)
|
||||
|
||||
if (matchingRoom) {
|
||||
return {
|
||||
description: matchingRoom.mainBed.description,
|
||||
size: matchingRoom.mainBed.widthRange,
|
||||
value: matchingRoom.code,
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter((bed): bed is BedType => Boolean(bed))
|
||||
|
||||
selectedRoomAvailabilitySuccessCounter.add(1, {
|
||||
hotelId,
|
||||
roomStayStartDate,
|
||||
@@ -815,6 +852,7 @@ export const hotelQueryRouter = router({
|
||||
cancellationText,
|
||||
memberRate,
|
||||
publicRate,
|
||||
bedTypes,
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod"
|
||||
|
||||
import { bedTypeSchema } from "@/components/HotelReservation/EnterDetails/BedType/schema"
|
||||
|
||||
type BedType = {
|
||||
export type BedType = {
|
||||
description: string
|
||||
size: {
|
||||
min: number
|
||||
|
||||
Reference in New Issue
Block a user