Migrate to a monorepo setup - step 1 * Move web to subfolder /apps/scandic-web * Yarn + transitive deps - Move to yarn - design-system package removed for now since yarn doesn't support the parameter for token (ie project currently broken) - Add missing transitive dependencies as Yarn otherwise prevents these imports - VS Code doesn't pick up TS path aliases unless you open /apps/scandic-web instead of root (will be fixed with monorepo) * Pin framer-motion to temporarily fix typing issue https://github.com/adobe/react-spectrum/issues/7494 * Pin zod to avoid typ error There seems to have been a breaking change in the types returned by zod where error is now returned as undefined instead of missing in the type. We should just handle this but to avoid merge conflicts just pin the dependency for now. * Pin react-intl version Pin version of react-intl to avoid tiny type issue where formatMessage does not accept a generic any more. This will be fixed in a future commit, but to avoid merge conflicts just pin for now. * Pin typescript version Temporarily pin version as newer versions as stricter and results in a type error. Will be fixed in future commit after merge. * Setup workspaces * Add design-system as a monorepo package * Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN * Fix husky for monorepo setup * Update netlify.toml * Add lint script to root package.json * Add stub readme * Fix react-intl formatMessage types * Test netlify.toml in root * Remove root toml * Update netlify.toml publish path * Remove package-lock.json * Update build for branch/preview builds Approved-by: Linus Flood
167 lines
5.5 KiB
TypeScript
167 lines
5.5 KiB
TypeScript
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
|
import { notFound } from "next/navigation"
|
|
import { Suspense } from "react"
|
|
|
|
import { env } from "@/env/server"
|
|
import { getCityCoordinates } from "@/lib/trpc/memoizedRequests"
|
|
|
|
import {
|
|
fetchAlternativeHotels,
|
|
fetchAvailableHotels,
|
|
fetchBookingCodeAvailableHotels,
|
|
getFiltersFromHotels,
|
|
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
|
import { getHotelSearchDetails } from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/utils"
|
|
import TrackingSDK from "@/components/TrackingSDK"
|
|
import { getLang } from "@/i18n/serverContext"
|
|
import { safeTry } from "@/utils/safeTry"
|
|
|
|
import { getHotelPins } from "../../HotelCardDialogListing/utils"
|
|
import SelectHotelMap from "."
|
|
|
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
|
import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
|
import type { SelectHotelMapContainerProps } from "@/types/components/hotelReservation/selectHotel/map"
|
|
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
|
import {
|
|
TrackingChannelEnum,
|
|
type TrackingSDKHotelInfo,
|
|
type TrackingSDKPageData,
|
|
} from "@/types/components/tracking"
|
|
|
|
export async function SelectHotelMapContainer({
|
|
searchParams,
|
|
isAlternativeHotels,
|
|
}: SelectHotelMapContainerProps) {
|
|
const lang = getLang()
|
|
const googleMapId = env.GOOGLE_DYNAMIC_MAP_ID
|
|
const googleMapsApiKey = env.GOOGLE_STATIC_MAP_KEY
|
|
const getHotelSearchDetailsPromise = safeTry(
|
|
getHotelSearchDetails(
|
|
{
|
|
searchParams: searchParams as SelectHotelSearchParams & {
|
|
[key: string]: string
|
|
},
|
|
},
|
|
isAlternativeHotels
|
|
)
|
|
)
|
|
|
|
const [searchDetails] = await getHotelSearchDetailsPromise
|
|
|
|
if (!searchDetails) return notFound()
|
|
|
|
const {
|
|
city,
|
|
selectHotelParams,
|
|
adultsInRoom,
|
|
childrenInRoom,
|
|
childrenInRoomString,
|
|
hotel: isAlternativeFor,
|
|
bookingCode,
|
|
} = searchDetails
|
|
|
|
if (!city) return notFound()
|
|
|
|
const fetchAvailableHotelsPromise = isAlternativeFor
|
|
? safeTry(
|
|
fetchAlternativeHotels(isAlternativeFor.id, {
|
|
roomStayStartDate: selectHotelParams.fromDate,
|
|
roomStayEndDate: selectHotelParams.toDate,
|
|
adults: adultsInRoom[0],
|
|
children: childrenInRoomString,
|
|
bookingCode,
|
|
})
|
|
)
|
|
: bookingCode
|
|
? safeTry(
|
|
fetchBookingCodeAvailableHotels({
|
|
cityId: city.id,
|
|
roomStayStartDate: selectHotelParams.fromDate,
|
|
roomStayEndDate: selectHotelParams.toDate,
|
|
adults: adultsInRoom[0],
|
|
children: childrenInRoomString,
|
|
bookingCode,
|
|
})
|
|
)
|
|
: safeTry(
|
|
fetchAvailableHotels({
|
|
cityId: city.id,
|
|
roomStayStartDate: selectHotelParams.fromDate,
|
|
roomStayEndDate: selectHotelParams.toDate,
|
|
adults: adultsInRoom[0],
|
|
children: childrenInRoomString,
|
|
})
|
|
)
|
|
|
|
const [hotels] = await fetchAvailableHotelsPromise
|
|
|
|
const validHotels = (hotels?.filter(Boolean) as HotelData[]) || []
|
|
|
|
const hotelPins = getHotelPins(validHotels)
|
|
const filterList = getFiltersFromHotels(validHotels)
|
|
const cityCoordinates = await getCityCoordinates({
|
|
city: city.name,
|
|
hotel: { address: hotels?.[0]?.hotelData?.address.streetAddress },
|
|
})
|
|
|
|
const arrivalDate = new Date(selectHotelParams.fromDate)
|
|
const departureDate = new Date(selectHotelParams.toDate)
|
|
|
|
const pageTrackingData: TrackingSDKPageData = {
|
|
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
|
|
domainLanguage: lang,
|
|
channel: TrackingChannelEnum["hotelreservation"],
|
|
pageName: isAlternativeHotels
|
|
? "hotelreservation|alternative-hotels|mapview"
|
|
: "hotelreservation|select-hotel|mapview",
|
|
siteSections: isAlternativeHotels
|
|
? "hotelreservation|altervative-hotels|mapview"
|
|
: "hotelreservation|select-hotel|mapview",
|
|
pageType: "bookinghotelsmapviewpage",
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
|
availableResults: validHotels.length,
|
|
searchTerm: isAlternativeFor
|
|
? selectHotelParams.hotelId
|
|
: (selectHotelParams.city as string),
|
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
|
departureDate: format(departureDate, "yyyy-MM-dd"),
|
|
noOfAdults: adultsInRoom[0], // TODO: Handle multiple rooms
|
|
noOfChildren: childrenInRoom?.length,
|
|
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
|
|
childBedPreference: childrenInRoom
|
|
?.map((c) => ChildBedMapEnum[c.bed])
|
|
.join("|"),
|
|
noOfRooms: 1, // // TODO: Handle multiple rooms
|
|
duration: differenceInCalendarDays(departureDate, arrivalDate),
|
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
|
searchType: "destination",
|
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
|
country: validHotels?.[0]?.hotelData.address.country,
|
|
region: validHotels?.[0]?.hotelData.address.city,
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<SelectHotelMap
|
|
apiKey={googleMapsApiKey}
|
|
hotelPins={hotelPins}
|
|
mapId={googleMapId}
|
|
hotels={validHotels}
|
|
filterList={filterList}
|
|
cityCoordinates={cityCoordinates}
|
|
bookingCode={bookingCode ?? ""}
|
|
/>
|
|
<Suspense fallback={null}>
|
|
<TrackingSDK
|
|
pageData={pageTrackingData}
|
|
hotelInfo={hotelsTrackingData}
|
|
/>
|
|
</Suspense>
|
|
</>
|
|
)
|
|
}
|