feat(SW-2873): Move select-hotel to booking flow * crude setup of select-hotel in partner-sas * wip * Fix linting * restructure tracking files * Remove dependency on trpc in tracking hooks * Move pageview tracking to common * Fix some lint and import issues * Add AlternativeHotelsPage * Add SelectHotelMapPage * Add AlternativeHotelsMapPage * remove next dependency in tracking store * Remove dependency on react in tracking hooks * move isSameBooking to booking-flow * Inject searchParamsComparator into tracking store * Move useTrackHardNavigation to common * Move useTrackSoftNavigation to common * Add TrackingSDK to partner-sas * call serverclient in layout * Remove unused css * Update types * Move HotelPin type * Fix todos * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Fix component Approved-by: Joakim Jäderberg
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
|
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
|
import {
|
|
type HotelLocation,
|
|
isHotelLocation,
|
|
type Location,
|
|
} from "@scandic-hotels/trpc/types/locations"
|
|
|
|
import { getLocations } from "../trpc/memoizedRequests/getLocations"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
import type { Child } from "@scandic-hotels/trpc/types/child"
|
|
|
|
import type { BookingSearchType } from "./searchType"
|
|
|
|
interface HotelSearchDetails {
|
|
city: Location | null
|
|
cityIdentifier: string | undefined
|
|
hotel: HotelLocation | null
|
|
redemption?: boolean
|
|
}
|
|
|
|
export async function getHotelSearchDetails(params: {
|
|
hotelId?: string
|
|
city?: string
|
|
rooms?: {
|
|
adults: number
|
|
childrenInRoom?: Child[]
|
|
}[]
|
|
searchType?: BookingSearchType
|
|
isAlternativeHotels?: boolean
|
|
lang: Lang
|
|
}): Promise<HotelSearchDetails | null> {
|
|
const [locations, error] = await safeTry(getLocations(params.lang))
|
|
if (!locations || error) {
|
|
return null
|
|
}
|
|
|
|
const hotel = params.hotelId
|
|
? ((locations.find(
|
|
(location) =>
|
|
isHotelLocation(location) &&
|
|
"operaId" in location &&
|
|
location.operaId === params.hotelId
|
|
) as HotelLocation | undefined) ?? null)
|
|
: null
|
|
|
|
if (params.isAlternativeHotels && !hotel) {
|
|
return null
|
|
}
|
|
|
|
const cityIdentifier = params.isAlternativeHotels
|
|
? hotel?.relationships.city.cityIdentifier
|
|
: params.city
|
|
|
|
const city = cityIdentifier
|
|
? (locations.find(
|
|
(location) =>
|
|
"cityIdentifier" in location &&
|
|
location.cityIdentifier?.toLowerCase() ===
|
|
cityIdentifier.toLowerCase()
|
|
) ?? null)
|
|
: null
|
|
|
|
if (!city && !hotel) return null
|
|
if (params.isAlternativeHotels && (!city || !hotel)) return null
|
|
|
|
return {
|
|
city,
|
|
cityIdentifier,
|
|
hotel,
|
|
redemption: params.searchType === SEARCH_TYPE_REDEMPTION,
|
|
}
|
|
}
|