feat: get breakfast package from API

This commit is contained in:
Simon Emanuelsson
2024-10-28 10:12:03 +01:00
parent fc8844eb96
commit 62f549e85d
47 changed files with 718 additions and 210 deletions

View File

@@ -1,6 +1,7 @@
import { notFound } from "next/navigation"
import { notFound, redirect } from "next/navigation"
import {
getBreakfastPackages,
getCreditCardsSafely,
getHotelData,
getProfileSafely,
@@ -17,22 +18,32 @@ 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()
}
function isValidStep(step: string): step is StepEnum {
return Object.values(StepEnum).includes(step as StepEnum)
}
export default async function StepPage({
params,
}: PageArgs<LangParams & { step: StepEnum }>) {
const { step, lang } = 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("811", lang)
const hotel = await getHotelData(searchParams.hotel, params.lang)
const user = await getProfileSafely()
const savedCreditCards = await getCreditCardsSafely()
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
if (!isValidStep(step) || !hotel) {
if (!isValidStep(params.step) || !hotel) {
return notFound()
}
@@ -51,7 +62,7 @@ export default async function StepPage({
step={StepEnum.breakfast}
label={intl.formatMessage({ id: "Select breakfast options" })}
>
<Breakfast />
<Breakfast packages={breakfastPackages} />
</SectionAccordion>
<SectionAccordion
header="Details"