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