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

View File

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

View File

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

View File

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