refactor: url management in hotel reservation flow
This commit is contained in:
47
components/HotelReservation/utils.ts
Normal file
47
components/HotelReservation/utils.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||
|
||||
import { AllergyIcon, PetsIcon, WheelchairIcon } from "@/components/Icons"
|
||||
|
||||
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||
import {
|
||||
RoomPackageCodeEnum,
|
||||
type RoomPackageCodes,
|
||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import type { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
|
||||
export function getIconForFeatureCode(featureCode: RoomPackageCodes) {
|
||||
switch (featureCode) {
|
||||
case RoomPackageCodeEnum.ACCESSIBILITY_ROOM:
|
||||
return WheelchairIcon
|
||||
case RoomPackageCodeEnum.ALLERGY_ROOM:
|
||||
return AllergyIcon
|
||||
case RoomPackageCodeEnum.PET_ROOM:
|
||||
return PetsIcon
|
||||
default:
|
||||
return PetsIcon
|
||||
}
|
||||
}
|
||||
|
||||
export const bedTypeMap: Record<number, ChildBedTypeEnum> = {
|
||||
[ChildBedMapEnum.IN_ADULTS_BED]: ChildBedTypeEnum.ParentsBed,
|
||||
[ChildBedMapEnum.IN_CRIB]: ChildBedTypeEnum.Crib,
|
||||
[ChildBedMapEnum.IN_EXTRA_BED]: ChildBedTypeEnum.ExtraBed,
|
||||
[ChildBedMapEnum.UNKNOWN]: ChildBedTypeEnum.Unknown,
|
||||
}
|
||||
|
||||
export const invertedBedTypeMap: Record<ChildBedTypeEnum, string> = {
|
||||
[ChildBedTypeEnum.ParentsBed]: ChildBedMapEnum[ChildBedMapEnum.IN_ADULTS_BED],
|
||||
[ChildBedTypeEnum.Crib]: ChildBedMapEnum[ChildBedMapEnum.IN_CRIB],
|
||||
[ChildBedTypeEnum.ExtraBed]: ChildBedMapEnum[ChildBedMapEnum.IN_EXTRA_BED],
|
||||
[ChildBedTypeEnum.Unknown]: ChildBedMapEnum[ChildBedMapEnum.UNKNOWN],
|
||||
}
|
||||
|
||||
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(",")}]`
|
||||
}
|
||||
Reference in New Issue
Block a user