fixed issue where city and hotel is undefined or null

This commit is contained in:
Pontus Dreij
2024-12-13 13:57:44 +01:00
parent 20cbb4b0a0
commit 78bf7ef387
4 changed files with 16 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { SelectHotelMapContainer } from "@/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainer"
@@ -18,9 +19,11 @@ export default async function SelectHotelMapPage({
}: PageArgs<LangParams, SelectHotelSearchParams>) {
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return null
if (!searchDetails) return notFound()
const { city, adultsInRoom, childrenInRoom } = searchDetails
if (!city) return notFound()
return (
<div className={styles.main}>
<MapContainer>

View File

@@ -1,3 +1,4 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import SelectHotel from "@/components/HotelReservation/SelectHotel"
@@ -15,9 +16,11 @@ export default async function SelectHotelPage({
}: PageArgs<LangParams, SelectHotelSearchParams>) {
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return null
if (!searchDetails) return notFound()
const { city, urlSearchParams, adultsInRoom, childrenInRoom } = searchDetails
if (!city) return notFound()
const reservationParams = {
selectHotelParams: urlSearchParams,
searchParams,

View File

@@ -1,3 +1,4 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
@@ -17,9 +18,11 @@ export default async function SelectRatePage({
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return null
if (!searchDetails) return notFound()
const { hotel, adultsInRoom, childrenInRoomArray } = searchDetails
if (!hotel) return notFound()
const { fromDate, toDate } = getValidDates(
searchParams.fromDate,
searchParams.toDate

View File

@@ -15,8 +15,8 @@ import type {
import type { Location } from "@/types/trpc/routers/hotel/locations"
interface HotelSearchDetails {
city: Location
hotel: Location
city: Location | null
hotel: Location | null
urlSearchParams?: URLSearchParams
adultsInRoom: number
childrenInRoom?: string
@@ -67,8 +67,8 @@ export async function getHotelSearchDetails({
}
return {
city: city!,
hotel: hotel!,
city: city ?? null,
hotel: hotel ?? null,
urlSearchParams,
adultsInRoom,
childrenInRoom,