109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import { notFound, redirect } from "next/navigation"
|
|
|
|
import {
|
|
getBreakfastPackages,
|
|
getCreditCardsSafely,
|
|
getHotelData,
|
|
getProfileSafely,
|
|
getRoomAvailability,
|
|
} from "@/lib/trpc/memoizedRequests"
|
|
|
|
import BedType from "@/components/HotelReservation/EnterDetails/BedType"
|
|
import Breakfast from "@/components/HotelReservation/EnterDetails/Breakfast"
|
|
import Details from "@/components/HotelReservation/EnterDetails/Details"
|
|
import HistoryStateManager from "@/components/HotelReservation/EnterDetails/HistoryStateManager"
|
|
import Payment from "@/components/HotelReservation/EnterDetails/Payment"
|
|
import SectionAccordion from "@/components/HotelReservation/EnterDetails/SectionAccordion"
|
|
import { getIntl } from "@/i18n"
|
|
|
|
import { StepEnum } from "@/types/components/enterDetails/step"
|
|
import type { LangParams, PageArgs } from "@/types/params"
|
|
|
|
export function preload() {
|
|
void getProfileSafely()
|
|
void getCreditCardsSafely()
|
|
void getRoomAvailability("811", 1, "2024-11-01", "2024-11-02")
|
|
}
|
|
|
|
function isValidStep(step: string): step is StepEnum {
|
|
return Object.values(StepEnum).includes(step as StepEnum)
|
|
}
|
|
|
|
export default async function StepPage({
|
|
params,
|
|
searchParams,
|
|
}: PageArgs<LangParams & { step: StepEnum }, { hotel: string }>) {
|
|
if (!searchParams.hotel) {
|
|
redirect(`/${params.lang}`)
|
|
}
|
|
void getBreakfastPackages(searchParams.hotel)
|
|
|
|
const intl = await getIntl()
|
|
|
|
const hotel = await getHotelData(searchParams.hotel, params.lang)
|
|
const user = await getProfileSafely()
|
|
const savedCreditCards = await getCreditCardsSafely()
|
|
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
|
|
|
|
const roomAvailability = await getRoomAvailability(
|
|
searchParams.hotel,
|
|
Number(searchParams.adults),
|
|
searchParams.checkIn,
|
|
searchParams.checkOut
|
|
)
|
|
|
|
if (!isValidStep(params.step) || !hotel || !roomAvailability) {
|
|
return notFound()
|
|
}
|
|
|
|
const mustBeGuaranteed = false
|
|
|
|
return (
|
|
<section>
|
|
<HistoryStateManager />
|
|
<SectionAccordion
|
|
header="Select bed"
|
|
step={StepEnum.selectBed}
|
|
label={intl.formatMessage({ id: "Request bedtype" })}
|
|
>
|
|
<BedType />
|
|
</SectionAccordion>
|
|
<SectionAccordion
|
|
header="Food options"
|
|
step={StepEnum.breakfast}
|
|
label={intl.formatMessage({ id: "Select breakfast options" })}
|
|
>
|
|
<Breakfast packages={breakfastPackages} />
|
|
</SectionAccordion>
|
|
<SectionAccordion
|
|
header="Details"
|
|
step={StepEnum.details}
|
|
label={intl.formatMessage({ id: "Enter your details" })}
|
|
>
|
|
<Details user={user} />
|
|
</SectionAccordion>
|
|
<SectionAccordion
|
|
header={mustBeGuaranteed ? "Payment Guarantee" : "Payment"}
|
|
step={StepEnum.payment}
|
|
label={
|
|
mustBeGuaranteed
|
|
? intl.formatMessage({ id: "Guarantee booking with credit card" })
|
|
: intl.formatMessage({ id: "Select payment method" })
|
|
}
|
|
>
|
|
<Payment
|
|
hotelId={searchParams.hotel}
|
|
otherPaymentOptions={
|
|
mustBeGuaranteed
|
|
? []
|
|
: hotel.data.attributes.merchantInformationData
|
|
.alternatePaymentOptions
|
|
}
|
|
savedCreditCards={savedCreditCards}
|
|
mustBeGuaranteed={mustBeGuaranteed}
|
|
/>
|
|
</SectionAccordion>
|
|
</section>
|
|
)
|
|
}
|