fix: clean up hotel and its typings

This commit is contained in:
Simon Emanuelsson
2024-12-17 16:17:25 +01:00
parent ec74af8814
commit 13a164242f
110 changed files with 1931 additions and 1559 deletions

View File

@@ -12,6 +12,8 @@ export default async function BookingConfirmationPage({
setLang(params.lang)
void getBookingConfirmation(searchParams.confirmationNumber)
return (
<BookingConfirmation confirmationNumber={searchParams.confirmationNumber} />
<BookingConfirmation
confirmationNumber={searchParams.confirmationNumber}
/>
)
}

View File

@@ -1,4 +1,4 @@
import { getHotelData } from "@/lib/trpc/memoizedRequests"
import { getHotel } from "@/lib/trpc/memoizedRequests"
import SidePeek from "@/components/HotelReservation/SidePeek"
@@ -12,9 +12,10 @@ export default async function HotelSidePeek({
return <SidePeek hotel={null} />
}
const hotel = await getHotelData({
const hotel = await getHotel({
hotelId: searchParams.hotel,
language: params.lang,
isCardOnlyPayment: false,
})
return <SidePeek hotel={hotel} />

View File

@@ -1,4 +1,4 @@
import { getHotelData } from "@/lib/trpc/memoizedRequests"
import { getHotel } from "@/lib/trpc/memoizedRequests"
import { serverClient } from "@/lib/trpc/server"
import { getLang } from "@/i18n/serverContext"
@@ -73,15 +73,16 @@ async function enhanceHotels(hotels: {
const language = getLang()
const hotelFetchers = hotels.availability.map(async (hotel) => {
const hotelData = await getHotelData({
const hotelData = await getHotel({
hotelId: hotel.hotelId.toString(),
isCardOnlyPayment: false,
language,
})
if (!hotelData) return { hotelData: null, price: hotel.productType }
return {
hotelData: hotelData.data.attributes,
hotelData: hotelData.hotel,
price: hotel.productType,
}
})

View File

@@ -2,7 +2,7 @@ import { differenceInCalendarDays, format, isWeekend } from "date-fns"
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { getHotelData } from "@/lib/trpc/memoizedRequests"
import { getHotel } from "@/lib/trpc/memoizedRequests"
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/Rooms/RoomsContainer"
@@ -28,13 +28,16 @@ export default async function SelectRatePage({
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return notFound()
const { hotel, adultsInRoom, childrenInRoom, selectHotelParams } =
searchDetails
if (!searchDetails) {
return notFound()
}
const { hotel, adultsInRoom, childrenInRoom, selectHotelParams } = searchDetails
if (!hotel) return notFound()
if (!hotel) {
return notFound()
}
const hotelData = await getHotelData({
const hotelData = await getHotel({
hotelId: hotel.id,
language: params.lang,
})
@@ -72,9 +75,9 @@ export default async function SelectRatePage({
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
searchType: "hotel",
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
country: hotelData?.data?.attributes.address.country,
country: hotelData?.hotel.address.country,
hotelID: hotel?.id,
region: hotelData?.data?.attributes.address.city,
region: hotelData?.hotel.address.city,
}
const hotelId = +hotel.id

View File

@@ -16,8 +16,8 @@ import {
type TrackingSDKUserData,
} from "@/types/components/tracking"
import type { Packages } from "@/types/requests/packages"
import type { RoomConfiguration } from "@/types/trpc/routers/hotel/roomAvailability"
import type { Lang } from "@/constants/languages"
import type { RoomConfiguration } from "@/server/routers/hotels/output"
type Props = {
initialHotelsTrackingData: TrackingSDKHotelInfo
@@ -135,7 +135,7 @@ export default function EnterDetailsTracking(props: Props) {
roomPrice: roomPrice.perStay.local.price,
discount: roomRate.memberRate
? roomRate.publicRate.localPrice.pricePerStay -
roomRate.memberRate.localPrice.pricePerStay
roomRate.memberRate.localPrice.pricePerStay
: 0,
analyticsrateCode: getAnalyticsRateCode(roomRate.publicRate.rateCode),
ancillaries: breakfastAncillary ? [breakfastAncillary] : [],

View File

@@ -4,7 +4,7 @@ import { Suspense } from "react"
import {
getBreakfastPackages,
getHotelData,
getHotel,
getPackages,
getProfileSafely,
getSelectedRoomAvailability,
@@ -106,19 +106,19 @@ export default async function StepPage({
const packages = packageCodes
? await getPackages({
adults,
children: childrenInRoom?.length,
endDate: toDate,
hotelId,
packageCodes,
startDate: fromDate,
})
adults,
children: childrenInRoom?.length,
endDate: toDate,
hotelId,
packageCodes,
startDate: fromDate,
})
: null
const roomAvailability = await getSelectedRoomAvailability(
selectedRoomAvailabilityInput
)
const hotelData = await getHotelData({
const hotelData = await getHotel({
hotelId,
isCardOnlyPayment: roomAvailability?.mustBeGuaranteed,
language: lang,
@@ -153,14 +153,14 @@ export default async function StepPage({
const memberPrice = roomAvailability.memberRate
? {
price: roomAvailability.memberRate.localPrice.pricePerStay,
currency: roomAvailability.memberRate.localPrice.currency,
}
price: roomAvailability.memberRate.localPrice.pricePerStay,
currency: roomAvailability.memberRate.localPrice.currency,
}
: undefined
const arrivalDate = new Date(fromDate)
const departureDate = new Date(toDate)
const hotelAttributes = hotelData?.data.attributes
const arrivalDate = new Date(searchParams.fromDate)
const departureDate = new Date(searchParams.toDate)
const hotelAttributes = hotelData?.hotel
const initialHotelsTrackingData: TrackingSDKHotelInfo = {
searchTerm: searchParams.city,
@@ -207,7 +207,7 @@ export default async function StepPage({
searchParamsStr={selectRoomParams.toString()}
step={searchParams.step}
user={user}
vat={hotelData.data.attributes.vat}
vat={hotelAttributes.vat}
>
<main>
<HotelHeader hotelData={hotelData} />
@@ -262,11 +262,11 @@ export default async function StepPage({
user={user}
roomPrice={roomPrice}
otherPaymentOptions={
hotelData.data.attributes.merchantInformationData
hotelData.hotel.merchantInformationData
.alternatePaymentOptions
}
supportedCards={
hotelData.data.attributes.merchantInformationData.cards
hotelData.hotel.merchantInformationData.cards
}
mustBeGuaranteed={mustBeGuaranteed}
/>

View File

@@ -1,5 +1,5 @@
import { env } from "@/env/server"
import { getHotelData, getHotelPage } from "@/lib/trpc/memoizedRequests"
import { getHotel, getHotelPage } from "@/lib/trpc/memoizedRequests"
import BookingWidget, { preload } from "@/components/BookingWidget"
import { getLang } from "@/i18n/serverContext"
@@ -21,7 +21,7 @@ export default async function BookingWidgetPage({
if (params.contentType === PageContentTypeEnum.hotelPage) {
const hotelPageData = await getHotelPage()
const hotelData = await getHotelData({
const hotelData = await getHotel({
hotelId: hotelPageData?.hotel_page_id || "",
language: getLang(),
})