Merged in feat/sw-3207-refactor-select-hotel-tracking (pull request #2587)
feat(SW-3207): Refactor select-hotel tracking * Refactor select-hotel tracking Approved-by: Bianca Widstam
This commit is contained in:
@@ -2,7 +2,6 @@ import { notFound } from "next/navigation"
|
||||
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
||||
import { generateChildrenString } from "@scandic-hotels/trpc/routers/hotels/helpers"
|
||||
import {
|
||||
type HotelLocation,
|
||||
isHotelLocation,
|
||||
@@ -15,17 +14,11 @@ import type { BookingSearchType } from "@scandic-hotels/booking-flow/searchType"
|
||||
import type { Child } from "@scandic-hotels/trpc/types/child"
|
||||
|
||||
export type ChildrenInRoom = (Child[] | null)[] | null
|
||||
export type ChildrenInRoomString = (string | null)[] | null
|
||||
|
||||
interface HotelSearchDetails {
|
||||
adultsInRoom: number[]
|
||||
bookingCode?: string
|
||||
childrenInRoom: ChildrenInRoom
|
||||
childrenInRoomString: ChildrenInRoomString
|
||||
city: Location | null
|
||||
cityIdentifier: string | undefined
|
||||
hotel: HotelLocation | null
|
||||
noOfRooms: number
|
||||
redemption?: boolean
|
||||
}
|
||||
|
||||
@@ -37,7 +30,6 @@ export async function getHotelSearchDetails(
|
||||
adults: number
|
||||
childrenInRoom?: Child[]
|
||||
}[]
|
||||
bookingCode?: string
|
||||
searchType?: BookingSearchType
|
||||
},
|
||||
isAlternativeHotels?: boolean
|
||||
@@ -76,30 +68,10 @@ export async function getHotelSearchDetails(
|
||||
if (!city && !hotel) return notFound()
|
||||
if (isAlternativeHotels && (!city || !hotel)) return notFound()
|
||||
|
||||
let adultsInRoom: number[] = []
|
||||
let childrenInRoom: ChildrenInRoom = null
|
||||
let childrenInRoomString: ChildrenInRoomString = null
|
||||
|
||||
const { rooms } = params
|
||||
|
||||
if (rooms?.length) {
|
||||
adultsInRoom = rooms.map((room) => room.adults ?? 0)
|
||||
|
||||
childrenInRoom = rooms.map((room) => room.childrenInRoom ?? null)
|
||||
childrenInRoomString = rooms.map((room) =>
|
||||
room.childrenInRoom ? generateChildrenString(room.childrenInRoom) : null
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
adultsInRoom,
|
||||
bookingCode: params.bookingCode ?? undefined,
|
||||
childrenInRoom,
|
||||
childrenInRoomString,
|
||||
city,
|
||||
cityIdentifier,
|
||||
hotel,
|
||||
noOfRooms: rooms?.length ?? 0,
|
||||
redemption: params.searchType === SEARCH_TYPE_REDEMPTION,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user