diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx index ee900219e..b39c2622b 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx @@ -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 ( 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 ) } } diff --git a/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx b/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx index f219293ab..d8e541eb3 100644 --- a/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx +++ b/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx @@ -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, }, ] diff --git a/components/HotelReservation/SelectRate/RoomSelection/utils.ts b/components/HotelReservation/SelectRate/RoomSelection/utils.ts index 3f02f5f67..aa6ef2810 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/utils.ts +++ b/components/HotelReservation/SelectRate/RoomSelection/utils.ts @@ -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 = { - [BedTypeEnum.IN_ADULTS_BED]: "ParentsBed", - [BedTypeEnum.IN_CRIB]: "Crib", - [BedTypeEnum.IN_EXTRA_BED]: "ExtraBed", +export const bedTypeMap: Record = { + [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[], diff --git a/constants/booking.ts b/constants/booking.ts index da6b30695..c99ca3d0e 100644 --- a/constants/booking.ts +++ b/constants/booking.ts @@ -15,7 +15,7 @@ export enum BookingStatusEnum { PendingPayment = "PendingPayment", } -export enum BedTypeEnum { +export enum ChildBedTypeEnum { Crib = "Crib", ExtraBed = "ExtraBed", ParentsBed = "ParentsBed", diff --git a/server/routers/booking/input.ts b/server/routers/booking/input.ts index 0ea7f4476..61f552f57 100644 --- a/server/routers/booking/input.ts +++ b/server/routers/booking/input.ts @@ -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([]), diff --git a/server/routers/booking/output.ts b/server/routers/booking/output.ts index cf4536a0d..e67c8805b 100644 --- a/server/routers/booking/output.ts +++ b/server/routers/booking/output.ts @@ -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(), diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index a22e2a033..5ab05e976 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -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({ diff --git a/stores/guests-rooms.ts b/stores/guests-rooms.ts index bc305db61..04cfbc3ec 100644 --- a/stores/guests-rooms.ts +++ b/stores/guests-rooms.ts @@ -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 diff --git a/types/components/bookingWidget/enums.ts b/types/components/bookingWidget/enums.ts index ae63ad571..381be9b2f 100644 --- a/types/components/bookingWidget/enums.ts +++ b/types/components/bookingWidget/enums.ts @@ -1,4 +1,4 @@ -export enum BedTypeEnum { +export enum ChildBedMapEnum { IN_ADULTS_BED = 0, IN_CRIB = 1, IN_EXTRA_BED = 2, diff --git a/types/components/hotelReservation/selectRate/selectRate.ts b/types/components/hotelReservation/selectRate/selectRate.ts index d1e291459..ba8f3f45c 100644 --- a/types/components/hotelReservation/selectRate/selectRate.ts +++ b/types/components/hotelReservation/selectRate/selectRate.ts @@ -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 }