55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { getFormattedUrlQueryParams } from "@/utils/url"
|
|
|
|
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
|
import type {
|
|
Child,
|
|
SelectRateSearchParams,
|
|
} from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
|
|
export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
|
return getFormattedUrlQueryParams(searchParams, {
|
|
adults: "number",
|
|
age: "number",
|
|
}) as SelectRateSearchParams
|
|
}
|
|
|
|
const bedTypeMap: Record<number, string> = {
|
|
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
|
|
[BedTypeEnum.IN_CRIB]: "Crib",
|
|
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
|
|
}
|
|
|
|
export function generateChildrenString(children: Child[]): string {
|
|
return `[${children
|
|
.map((child) => {
|
|
const age = child.age
|
|
const bedType = bedTypeMap[parseInt(child.bed.toString())]
|
|
return `${age}:${bedType}`
|
|
})
|
|
.join(",")}]`
|
|
}
|
|
|
|
export function mapChildrenFromString(rawChildrenString: string) {
|
|
const children = rawChildrenString.split(",")
|
|
return children.map((child) => {
|
|
const [age, bed] = child.split(":")
|
|
return {
|
|
age: parseInt(age),
|
|
bed: BedTypeEnum[bed as keyof typeof BedTypeEnum],
|
|
}
|
|
})
|
|
}
|
|
|
|
export function getQueryParamsForEnterDetails(searchParams: URLSearchParams) {
|
|
const selectRoomParamsObject = getHotelReservationQueryParams(searchParams)
|
|
|
|
const { room } = selectRoomParamsObject
|
|
return {
|
|
...selectRoomParamsObject,
|
|
adults: room[0].adults, // TODO: Handle multiple rooms
|
|
children: room[0].child, // TODO: Handle multiple rooms and children
|
|
roomTypeCode: room[0].roomtype,
|
|
rateCode: room[0].ratecode,
|
|
}
|
|
}
|