fix: rename BedTypeEnums

This commit is contained in:
Christel Westerberg
2024-11-06 13:08:15 +01:00
parent 6d051629d3
commit f4f771ec70
12 changed files with 68 additions and 72 deletions

View File

@@ -7,7 +7,6 @@ import Summary from "@/components/HotelReservation/EnterDetails/Summary"
import {
generateChildrenString,
getQueryParamsForEnterDetails,
mapChildrenFromString,
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
@@ -39,27 +38,28 @@ export default async function SummaryPage({
return null
}
const prices = user && availability.memberRate
? {
local: {
price: availability.memberRate?.localPrice.pricePerStay,
currency: availability.memberRate?.localPrice.currency,
},
euro: {
price: availability.memberRate?.requestedPrice?.pricePerStay,
currency: availability.memberRate?.requestedPrice?.currency,
},
}
: {
local: {
price: availability.publicRate?.localPrice.pricePerStay,
currency: availability.publicRate?.localPrice.currency,
},
euro: {
price: availability.publicRate?.requestedPrice?.pricePerStay,
currency: availability.publicRate?.requestedPrice?.currency,
},
}
const prices =
user && availability.memberRate
? {
local: {
price: availability.memberRate?.localPrice.pricePerStay,
currency: availability.memberRate?.localPrice.currency,
},
euro: {
price: availability.memberRate?.requestedPrice?.pricePerStay,
currency: availability.memberRate?.requestedPrice?.currency,
},
}
: {
local: {
price: availability.publicRate?.localPrice.pricePerStay,
currency: availability.publicRate?.localPrice.currency,
},
euro: {
price: availability.publicRate?.requestedPrice?.pricePerStay,
currency: availability.publicRate?.requestedPrice?.currency,
},
}
return (
<Summary

View File

@@ -136,7 +136,6 @@ export default async function StepPage({
label={mustBeGuaranteed ? guaranteeWithCard : selectPaymentMethod}
>
<Payment
hotelId={searchParams.hotel}
otherPaymentOptions={
hotelData.data.attributes.merchantInformationData
.alternatePaymentOptions

View File

@@ -11,7 +11,7 @@ import Counter from "../Counter"
import styles from "./adult-selector.module.css"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
import {
AdultSelectorProps,
Child,
@@ -40,14 +40,14 @@ export default function AdultSelector({ roomIndex = 0 }: AdultSelectorProps) {
setValue(`rooms.${roomIndex}.adults`, adults - 1)
if (childrenInAdultsBed > adults) {
const toUpdateIndex = child.findIndex(
(child: Child) => child.bed == BedTypeEnum.IN_ADULTS_BED
(child: Child) => child.bed == ChildBedMapEnum.IN_ADULTS_BED
)
if (toUpdateIndex != -1) {
setValue(
`rooms.${roomIndex}.children.${toUpdateIndex}.bed`,
child[toUpdateIndex].age < 3
? BedTypeEnum.IN_CRIB
: BedTypeEnum.IN_EXTRA_BED
? ChildBedMapEnum.IN_CRIB
: ChildBedMapEnum.IN_EXTRA_BED
)
}
}

View File

@@ -11,7 +11,7 @@ import Caption from "@/components/TempDesignSystem/Text/Caption"
import styles from "./child-selector.module.css"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
import {
ChildBed,
ChildInfoSelectorProps,
@@ -59,9 +59,9 @@ export default function ChildInfoSelector({
}
function updateSelectedBed(bed: number) {
if (bed == BedTypeEnum.IN_ADULTS_BED) {
if (bed == ChildBedMapEnum.IN_ADULTS_BED) {
increaseChildInAdultsBed(roomIndex)
} else if (child.bed == BedTypeEnum.IN_ADULTS_BED) {
} else if (child.bed == ChildBedMapEnum.IN_ADULTS_BED) {
decreaseChildInAdultsBed(roomIndex)
}
updateChildBed(bed, roomIndex, index)
@@ -71,15 +71,15 @@ export default function ChildInfoSelector({
const allBedTypes: ChildBed[] = [
{
label: intl.formatMessage({ id: "In adults bed" }),
value: BedTypeEnum.IN_ADULTS_BED,
value: ChildBedMapEnum.IN_ADULTS_BED,
},
{
label: intl.formatMessage({ id: "In crib" }),
value: BedTypeEnum.IN_CRIB,
value: ChildBedMapEnum.IN_CRIB,
},
{
label: intl.formatMessage({ id: "In extra bed" }),
value: BedTypeEnum.IN_EXTRA_BED,
value: ChildBedMapEnum.IN_EXTRA_BED,
},
]

View File

@@ -1,6 +1,8 @@
import { ChildBedTypeEnum } from "@/constants/booking"
import { getFormattedUrlQueryParams } from "@/utils/url"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
import { BookingData } from "@/types/components/hotelReservation/enterDetails/bookingData"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import type {
@@ -12,13 +14,14 @@ export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
return getFormattedUrlQueryParams(searchParams, {
adults: "number",
age: "number",
bed: ChildBedMapEnum,
}) as SelectRateSearchParams
}
const bedTypeMap: Record<number, string> = {
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
[BedTypeEnum.IN_CRIB]: "Crib",
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
export const bedTypeMap: Record<number, ChildBedTypeEnum> = {
[ChildBedMapEnum.IN_ADULTS_BED]: ChildBedTypeEnum.ParentsBed,
[ChildBedMapEnum.IN_CRIB]: ChildBedTypeEnum.Crib,
[ChildBedMapEnum.IN_EXTRA_BED]: ChildBedTypeEnum.ExtraBed,
}
export function generateChildrenString(children: Child[]): string {
@@ -31,17 +34,6 @@ export function generateChildrenString(children: Child[]): string {
.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
): BookingData {
@@ -49,10 +41,12 @@ export function getQueryParamsForEnterDetails(
const { room } = selectRoomParamsObject
return {
...selectRoomParamsObject,
fromDate: selectRoomParamsObject.fromDate,
toDate: selectRoomParamsObject.toDate,
hotel: selectRoomParamsObject.hotel,
rooms: room.map((room) => ({
adults: room.adults, // TODO: Handle multiple rooms
child: room.child, // TODO: Handle multiple rooms and children
children: room.child, // TODO: Handle multiple rooms and children
roomTypeCode: room.roomtype,
rateCode: room.ratecode,
packages: room.packages?.split(",") as RoomPackageCodeEnum[],

View File

@@ -15,7 +15,7 @@ export enum BookingStatusEnum {
PendingPayment = "PendingPayment",
}
export enum BedTypeEnum {
export enum ChildBedTypeEnum {
Crib = "Crib",
ExtraBed = "ExtraBed",
ParentsBed = "ParentsBed",

View File

@@ -1,5 +1,7 @@
import { z } from "zod"
import { ChildBedTypeEnum } from "@/constants/booking"
const roomsSchema = z.array(
z.object({
adults: z.number().int().nonnegative(),
@@ -7,7 +9,7 @@ const roomsSchema = z.array(
.array(
z.object({
age: z.number().int().nonnegative(),
bedType: z.string(),
bedType: z.nativeEnum(ChildBedTypeEnum),
})
)
.default([]),

View File

@@ -1,6 +1,6 @@
import { z } from "zod"
import { BedTypeEnum } from "@/constants/booking"
import { ChildBedTypeEnum } from "@/constants/booking"
// MUTATION
export const createBookingSchema = z
@@ -36,9 +36,9 @@ export const createBookingSchema = z
}))
// QUERY
const childrenAgesSchema = z.object({
age: z.number(),
bedType: z.nativeEnum(BedTypeEnum),
const extraBedTypesSchema = z.object({
quantity: z.number(),
bedType: z.nativeEnum(ChildBedTypeEnum),
})
const guestSchema = z.object({
@@ -65,7 +65,8 @@ export const bookingConfirmationSchema = z
checkInDate: z.date({ coerce: true }),
checkOutDate: z.date({ coerce: true }),
createDateTime: z.date({ coerce: true }),
childrenAges: z.array(childrenAgesSchema),
childrenAges: z.array(z.number()),
extraBedTypes: z.array(extraBedTypesSchema),
computedReservationStatus: z.string(),
confirmationNumber: z.string(),
currencyCode: z.string(),

View File

@@ -1,6 +1,6 @@
import { z } from "zod"
import { BedTypeEnum } from "@/constants/booking"
import { ChildBedTypeEnum } from "@/constants/booking"
import { dt } from "@/lib/dt"
import { toLang } from "@/server/utils"
@@ -441,7 +441,7 @@ export const getHotelDataSchema = z.object({
export const childrenSchema = z.object({
age: z.number(),
bedType: z.nativeEnum(BedTypeEnum),
bedType: z.nativeEnum(ChildBedTypeEnum),
})
const occupancySchema = z.object({

View File

@@ -4,7 +4,7 @@ import { produce } from "immer"
import { createContext, useContext } from "react"
import { create, useStore } from "zustand"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
import {
Child,
GuestsRoom,
@@ -41,15 +41,15 @@ export function validateBedTypes(data: extendedGuestsRoom[]) {
room.child.forEach((child) => {
const allowedBedTypes: number[] = []
if (child.age <= 5 && room.adults >= room.childrenInAdultsBed) {
allowedBedTypes.push(BedTypeEnum.IN_ADULTS_BED)
allowedBedTypes.push(ChildBedMapEnum.IN_ADULTS_BED)
} else if (child.age <= 5) {
room.childrenInAdultsBed = room.childrenInAdultsBed - 1
}
if (child.age < 3) {
allowedBedTypes.push(BedTypeEnum.IN_CRIB)
allowedBedTypes.push(ChildBedMapEnum.IN_CRIB)
}
if (child.age > 2) {
allowedBedTypes.push(BedTypeEnum.IN_EXTRA_BED)
allowedBedTypes.push(ChildBedMapEnum.IN_EXTRA_BED)
}
if (!allowedBedTypes.includes(child.bed)) {
child.bed = allowedBedTypes[0]
@@ -84,7 +84,7 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
inputData.rooms = initData.map((room) => {
const childrenInAdultsBed = room.child
? room.child.reduce((acc, child) => {
acc = acc + (child.bed == BedTypeEnum.IN_ADULTS_BED ? 1 : 0)
acc = acc + (child.bed == ChildBedMapEnum.IN_ADULTS_BED ? 1 : 0)
return acc
}, 0)
: 0
@@ -121,13 +121,13 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
state.rooms[roomIndex].adults
) {
const toUpdateIndex = state.rooms[roomIndex].child.findIndex(
(child) => child.bed == BedTypeEnum.IN_ADULTS_BED
(child) => child.bed == ChildBedMapEnum.IN_ADULTS_BED
)
if (toUpdateIndex != -1) {
state.rooms[roomIndex].child[toUpdateIndex].bed =
state.rooms[roomIndex].child[toUpdateIndex].age < 3
? BedTypeEnum.IN_CRIB
: BedTypeEnum.IN_EXTRA_BED
? ChildBedMapEnum.IN_CRIB
: ChildBedMapEnum.IN_EXTRA_BED
state.rooms[roomIndex].childrenInAdultsBed =
state.rooms[roomIndex].adults
}
@@ -151,7 +151,7 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
if (
roomChildren.length &&
roomChildren[roomChildren.length - 1].bed ==
BedTypeEnum.IN_ADULTS_BED
ChildBedMapEnum.IN_ADULTS_BED
) {
state.rooms[roomIndex].childrenInAdultsBed =
state.rooms[roomIndex].childrenInAdultsBed - 1

View File

@@ -1,4 +1,4 @@
export enum BedTypeEnum {
export enum ChildBedMapEnum {
IN_ADULTS_BED = 0,
IN_CRIB = 1,
IN_EXTRA_BED = 2,

View File

@@ -1,9 +1,9 @@
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
import { BedTypeEnum } from "../../bookingWidget/enums"
import { ChildBedMapEnum } from "../../bookingWidget/enums"
export interface Child {
bed: BedTypeEnum
bed: ChildBedMapEnum
age: number
}