fix: move crunching of data to trpc layer
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
getHotelData,
|
||||
getProfileSafely,
|
||||
getRoomAvailability,
|
||||
getSelectedRoomAvailability,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
import { HotelIncludeEnum } from "@/server/routers/hotels/input"
|
||||
|
||||
@@ -36,9 +37,7 @@ export default async function StepPage({
|
||||
searchParams,
|
||||
}: PageArgs<LangParams & { step: StepEnum }, SelectRateSearchParams>) {
|
||||
const { lang } = params
|
||||
if (!searchParams.hotel) {
|
||||
redirect(`/${lang}`)
|
||||
}
|
||||
|
||||
void getBreakfastPackages(searchParams.hotel)
|
||||
|
||||
const intl = await getIntl()
|
||||
@@ -62,24 +61,37 @@ export default async function StepPage({
|
||||
rateCode
|
||||
})
|
||||
|
||||
const hotelData = await getHotelData({
|
||||
hotelId,
|
||||
language: lang,
|
||||
include: [HotelIncludeEnum.RoomCategories],
|
||||
})
|
||||
|
||||
const user = await getProfileSafely()
|
||||
const savedCreditCards = await getCreditCardsSafely()
|
||||
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
|
||||
if (!rateCode || !roomTypeCode) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const roomAvailability = await getRoomAvailability({
|
||||
hotelId: parseInt(hotelId),
|
||||
adults,
|
||||
children,
|
||||
roomStayStartDate: fromDate,
|
||||
roomStayEndDate: toDate,
|
||||
rateCode
|
||||
})
|
||||
const [
|
||||
hotelData,
|
||||
user,
|
||||
savedCreditCards,
|
||||
breakfastPackages,
|
||||
roomAvailability,
|
||||
] = await Promise.all([
|
||||
getHotelData({
|
||||
hotelId,
|
||||
language: lang,
|
||||
include: [HotelIncludeEnum.RoomCategories],
|
||||
}),
|
||||
|
||||
getProfileSafely(),
|
||||
getCreditCardsSafely(),
|
||||
getBreakfastPackages(searchParams.hotel),
|
||||
getSelectedRoomAvailability({
|
||||
hotelId: parseInt(searchParams.hotel),
|
||||
adults,
|
||||
children,
|
||||
roomStayStartDate: fromDate,
|
||||
roomStayEndDate: toDate,
|
||||
rateCode,
|
||||
roomTypeCode,
|
||||
}),
|
||||
])
|
||||
|
||||
if (!isValidStep(params.step) || !hotelData || !roomAvailability) {
|
||||
return notFound()
|
||||
@@ -100,10 +112,8 @@ export default async function StepPage({
|
||||
id: "Select payment method",
|
||||
})
|
||||
|
||||
const availableRoom = roomAvailability?.roomConfigurations
|
||||
.filter((room) => room.status === "Available")
|
||||
.find((room) => room.roomTypeCode === roomTypeCode)?.roomType
|
||||
const roomTypes = hotelData.included
|
||||
const availableRoom = roomAvailability.selectedRoom?.roomType
|
||||
const bedTypes = hotelData.included
|
||||
?.find((room) => room.name === availableRoom)
|
||||
?.roomTypes.map((room) => ({
|
||||
description: room.mainBed.description,
|
||||
@@ -116,13 +126,13 @@ export default async function StepPage({
|
||||
<HistoryStateManager />
|
||||
|
||||
{/* TODO: How to handle no beds found? */}
|
||||
{roomTypes ? (
|
||||
{bedTypes ? (
|
||||
<SectionAccordion
|
||||
header="Select bed"
|
||||
step={StepEnum.selectBed}
|
||||
label={intl.formatMessage({ id: "Request bedtype" })}
|
||||
>
|
||||
<BedType roomTypes={roomTypes} />
|
||||
<BedType bedTypes={bedTypes} />
|
||||
</SectionAccordion>
|
||||
) : null}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user