fix: handle children in enter details
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { getFormattedUrlQueryParams } from "@/utils/url"
|
||||
|
||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
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, {
|
||||
@@ -9,6 +13,33 @@ export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
||||
}) 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)
|
||||
|
||||
@@ -16,7 +47,7 @@ export function getQueryParamsForEnterDetails(searchParams: URLSearchParams) {
|
||||
return {
|
||||
...selectRoomParamsObject,
|
||||
adults: room[0].adults, // TODO: Handle multiple rooms
|
||||
children: room[0].child?.length.toString(), // TODO: Handle multiple rooms and children
|
||||
children: room[0].child, // TODO: Handle multiple rooms and children
|
||||
roomTypeCode: room[0].roomtype,
|
||||
rateCode: room[0].ratecode,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user