89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import {
|
|
getHotelData,
|
|
getProfileSafely,
|
|
getRoomAvailability,
|
|
} from "@/lib/trpc/memoizedRequests"
|
|
import { HotelIncludeEnum } from "@/server/routers/hotels/input"
|
|
|
|
import Summary from "@/components/HotelReservation/EnterDetails/Summary"
|
|
import { getQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
|
import { formatNumber } from "@/utils/format"
|
|
|
|
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
|
|
|
export default async function SummaryPage({
|
|
params,
|
|
searchParams,
|
|
}: PageArgs<LangParams, SearchParams<SelectRateSearchParams>>) {
|
|
const selectRoomParams = new URLSearchParams(searchParams)
|
|
const { hotel, adults, children, roomTypeCode, rateCode, fromDate, toDate } =
|
|
getQueryParamsForEnterDetails(selectRoomParams)
|
|
|
|
const [user, hotelData, availability] = await Promise.all([
|
|
getProfileSafely(),
|
|
getHotelData({
|
|
hotelId: hotel,
|
|
language: params.lang,
|
|
include: [HotelIncludeEnum.RoomCategories],
|
|
}),
|
|
getRoomAvailability({
|
|
hotelId: parseInt(hotel),
|
|
adults,
|
|
children,
|
|
roomStayStartDate: fromDate,
|
|
roomStayEndDate: toDate,
|
|
}),
|
|
])
|
|
|
|
if (!hotelData?.data || !hotelData?.included || !availability) {
|
|
console.error("No hotel or availability data", hotelData, availability)
|
|
// TODO: handle this case
|
|
return null
|
|
}
|
|
|
|
const cancellationText =
|
|
availability?.rateDefinitions.find((rate) => rate.rateCode === rateCode)
|
|
?.cancellationText ?? ""
|
|
const chosenRoom = availability.roomConfigurations.find(
|
|
(availRoom) => availRoom.roomTypeCode === roomTypeCode
|
|
)
|
|
|
|
if (!chosenRoom) {
|
|
// TODO: handle this case
|
|
console.error("No chosen room", chosenRoom)
|
|
return null
|
|
}
|
|
|
|
const memberRate = chosenRoom.products.find(
|
|
(rate) => rate.productType.member?.rateCode === rateCode
|
|
)?.productType.member
|
|
|
|
const publicRate = chosenRoom.products.find(
|
|
(rate) => rate.productType.public?.rateCode === rateCode
|
|
)?.productType.public
|
|
|
|
const prices = user
|
|
? {
|
|
local: memberRate?.localPrice.pricePerStay,
|
|
euro: memberRate?.requestedPrice?.pricePerStay,
|
|
}
|
|
: {
|
|
local: publicRate?.localPrice.pricePerStay,
|
|
euro: publicRate?.requestedPrice?.pricePerStay,
|
|
}
|
|
|
|
return (
|
|
<Summary
|
|
isMember={!!user}
|
|
room={{
|
|
roomType: chosenRoom.roomType,
|
|
localPrice: formatNumber(parseInt(prices.local ?? "0")),
|
|
euroPrice: formatNumber(parseInt(prices.euro ?? "0")),
|
|
adults,
|
|
cancellationText,
|
|
}}
|
|
/>
|
|
)
|
|
}
|