Merge remote-tracking branch 'origin' into feature/tracking

This commit is contained in:
Linus Flood
2024-12-16 09:11:28 +01:00
42 changed files with 630 additions and 325 deletions

View File

@@ -1,17 +1,13 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { getLocations } from "@/lib/trpc/memoizedRequests"
import { SelectHotelMapContainer } from "@/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainer"
import { SelectHotelMapContainerSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton"
import {
generateChildrenString,
getHotelReservationQueryParams,
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { MapContainer } from "@/components/MapContainer"
import { setLang } from "@/i18n/serverContext"
import { getHotelSearchDetails } from "../../utils"
import styles from "./page.module.css"
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
@@ -22,26 +18,13 @@ export default async function SelectHotelMapPage({
searchParams,
}: PageArgs<LangParams, SelectHotelSearchParams>) {
setLang(params.lang)
const locations = await getLocations()
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return notFound()
const { city, adultsInRoom, childrenInRoom, childrenInRoomArray } =
searchDetails
if (!locations || "error" in locations) {
return null
}
const city = locations.data.find(
(location) =>
location.name.toLowerCase() === searchParams.city.toLowerCase()
)
if (!city) return notFound()
const selectHotelParams = new URLSearchParams(searchParams)
const selectHotelParamsObject =
getHotelReservationQueryParams(selectHotelParams)
const adultsInRoom = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
const childrenInRoom = selectHotelParamsObject.room[0].child
? generateChildrenString(selectHotelParamsObject.room[0].child)
: undefined // TODO: Handle multiple rooms
const child = selectHotelParamsObject.room[0].child // TODO: Handle multiple rooms
return (
<div className={styles.main}>
<MapContainer>
@@ -54,7 +37,7 @@ export default async function SelectHotelMapPage({
searchParams={searchParams}
adultsInRoom={adultsInRoom}
childrenInRoom={childrenInRoom}
child={child}
child={childrenInRoomArray}
/>
</Suspense>
</MapContainer>

View File

@@ -1,16 +1,13 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { getLocations } from "@/lib/trpc/memoizedRequests"
import SelectHotel from "@/components/HotelReservation/SelectHotel"
import { SelectHotelSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelSkeleton"
import {
generateChildrenString,
getHotelReservationQueryParams,
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { setLang } from "@/i18n/serverContext"
import { getHotelSearchDetails } from "../utils"
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
import type { LangParams, PageArgs } from "@/types/params"
@@ -19,46 +16,29 @@ export default async function SelectHotelPage({
searchParams,
}: PageArgs<LangParams, SelectHotelSearchParams>) {
setLang(params.lang)
const locations = await getLocations()
if (!locations || "error" in locations) {
return null
}
const city = locations.data.find(
(location) =>
location.name.toLowerCase() === searchParams.city.toLowerCase()
)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return notFound()
const {
city,
urlSearchParams,
adultsInRoom,
childrenInRoom,
childrenInRoomArray,
} = searchDetails
if (!city) return notFound()
const selectHotelParams = new URLSearchParams(searchParams)
const selectHotelParamsObject =
getHotelReservationQueryParams(selectHotelParams)
if (
!selectHotelParamsObject.room ||
selectHotelParamsObject.room.length === 0
) {
return notFound()
}
const adultsParams = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
const childrenParams = selectHotelParamsObject.room[0].child
? generateChildrenString(selectHotelParamsObject.room[0].child)
: undefined // TODO: Handle multiple rooms
const child = selectHotelParamsObject.room[0].child // TODO: Handle multiple rooms
const reservationParams = {
selectHotelParams,
selectHotelParams: urlSearchParams,
searchParams,
adultsParams,
childrenParams,
child,
adultsInRoom,
childrenInRoom,
childrenInRoomArray,
}
return (
<Suspense
key={`${city.name}-${searchParams.fromDate}-${searchParams.toDate}-${adultsParams}-${childrenParams}`}
key={`${city.name}-${searchParams.fromDate}-${searchParams.toDate}-${adultsInRoom}-${childrenInRoom}`}
fallback={<SelectHotelSkeleton />}
>
<SelectHotel

View File

@@ -2,16 +2,15 @@ import { differenceInCalendarDays, format, isWeekend } from "date-fns"
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { getHotelData, getLocations } from "@/lib/trpc/memoizedRequests"
import { getHotelData } from "@/lib/trpc/memoizedRequests"
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/Rooms/RoomsContainer"
import { RoomsContainerSkeleton } from "@/components/HotelReservation/SelectRate/Rooms/RoomsContainerSkeleton"
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import TrackingSDK from "@/components/TrackingSDK"
import { setLang } from "@/i18n/serverContext"
import { safeTry } from "@/utils/safeTry"
import { getHotelSearchDetails } from "../utils"
import { getValidDates } from "./getValidDates"
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
@@ -28,46 +27,24 @@ export default async function SelectRatePage({
searchParams,
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return notFound()
const { hotel, adultsInRoom, childrenInRoomArray } = searchDetails
const locations = await getLocations()
if (!locations || "error" in locations) {
return null
}
const hotel = locations.data.find(
(location) =>
"operaId" in location && location.operaId == searchParams.hotel
)
if (!hotel) {
return notFound()
}
const selectRoomParams = new URLSearchParams(searchParams)
const selectRoomParamsObject =
getHotelReservationQueryParams(selectRoomParams)
if (!hotel) return notFound()
if (!selectRoomParamsObject.room) {
return notFound()
}
const hotelData = await getHotelData({
hotelId: hotel.id,
language: params.lang,
})
const { fromDate, toDate } = getValidDates(
searchParams.fromDate,
searchParams.toDate
)
const adults = selectRoomParamsObject.room[0].adults || 1 // TODO: Handle multiple rooms
const children = selectRoomParamsObject.room[0].child // TODO: Handle multiple rooms
const [hotelData, hotelDataError] = await safeTry(
getHotelData({ hotelId: searchParams.hotel, language: params.lang })
)
if (!hotelData && !hotelDataError) {
return notFound()
}
const arrivalDate = new Date(searchParams.fromDate)
const departureDate = new Date(searchParams.toDate)
const hotelAttributes = hotelData?.data.attributes
const roomCategories = hotelData?.included
const pageTrackingData: TrackingSDKPageData = {
pageId: "select-rate",
@@ -80,26 +57,28 @@ export default async function SelectRatePage({
}
const hotelsTrackingData: TrackingSDKHotelInfo = {
searchTerm: searchParams.city ?? hotelAttributes?.name,
searchTerm: searchParams.city ?? hotel?.name,
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
departureDate: format(departureDate, "yyyy-MM-dd"),
noOfAdults: adults,
noOfChildren: children?.length,
ageOfChildren: children?.map((c) => c.age).join(","),
childBedPreference: children?.map((c) => ChildBedMapEnum[c.bed]).join("|"),
noOfAdults: adultsInRoom,
noOfChildren: childrenInRoomArray?.length,
ageOfChildren: childrenInRoomArray?.map((c) => c.age).join(","),
childBedPreference: childrenInRoomArray
?.map((c) => ChildBedMapEnum[c.bed])
.join("|"),
noOfRooms: 1, // // TODO: Handle multiple rooms
duration: differenceInCalendarDays(departureDate, arrivalDate),
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
searchType: "hotel",
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
country: hotelAttributes?.address.country,
hotelID: hotelAttributes?.operaId,
region: hotelAttributes?.address.city,
availableResults: roomCategories?.length,
country: hotelData?.data?.attributes.address.country,
hotelID: hotel?.id,
region: hotelData?.data?.attributes.address.city,
//availableResults: roomCategories?.length,
//lowestRoomPrice:
}
const hotelId = +searchParams.hotel
const hotelId = +hotel.id
return (
<>
@@ -108,8 +87,8 @@ export default async function SelectRatePage({
lang={params.lang}
fromDate={fromDate.toDate()}
toDate={toDate.toDate()}
adultCount={adults}
childArray={children}
adultCount={adultsInRoom}
childArray={childrenInRoomArray}
/>
<Suspense key={hotelId} fallback={<RoomsContainerSkeleton />}>
@@ -118,8 +97,8 @@ export default async function SelectRatePage({
lang={params.lang}
fromDate={fromDate.toDate()}
toDate={toDate.toDate()}
adultCount={adults}
childArray={children}
adultCount={adultsInRoom}
childArray={childrenInRoomArray}
/>
</Suspense>
<Suspense fallback={null}>

View File

@@ -0,0 +1,77 @@
import { notFound } from "next/navigation"
import { getLocations } from "@/lib/trpc/memoizedRequests"
import {
generateChildrenString,
getHotelReservationQueryParams,
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
import type {
Child,
SelectRateSearchParams,
} from "@/types/components/hotelReservation/selectRate/selectRate"
import type { Location } from "@/types/trpc/routers/hotel/locations"
interface HotelSearchDetails {
city: Location | null
hotel: Location | null
urlSearchParams?: URLSearchParams
adultsInRoom: number
childrenInRoom?: string
childrenInRoomArray?: Child[]
}
export async function getHotelSearchDetails({
searchParams,
}: {
searchParams:
| (SelectHotelSearchParams & {
[key: string]: string
})
| (SelectRateSearchParams & {
[key: string]: string
})
}): Promise<HotelSearchDetails | null> {
const locations = await getLocations()
if (!locations || "error" in locations) return null
const city = locations.data.find(
(location) =>
location.name.toLowerCase() === searchParams.city?.toLowerCase()
)
const hotel = locations.data.find(
(location) =>
"operaId" in location && location.operaId == searchParams.hotel
)
if (!city && !hotel) return notFound()
const urlSearchParams = new URLSearchParams(searchParams)
const searchParamsObject = getHotelReservationQueryParams(urlSearchParams)
let adultsInRoom = 1
let childrenInRoom: string | undefined = undefined
let childrenInRoomArray: Child[] | undefined = undefined
if (searchParamsObject.room && searchParamsObject.room.length > 0) {
adultsInRoom = searchParamsObject.room[0].adults // TODO: Handle multiple rooms
childrenInRoom = searchParamsObject.room[0].child
? generateChildrenString(searchParamsObject.room[0].child)
: undefined // TODO: Handle multiple rooms
childrenInRoomArray = searchParamsObject.room[0].child
? searchParamsObject.room[0].child
: undefined // TODO: Handle multiple rooms
}
return {
city: city ?? null,
hotel: hotel ?? null,
urlSearchParams,
adultsInRoom,
childrenInRoom,
childrenInRoomArray,
}
}