fix: rename BedTypeEnums
This commit is contained in:
@@ -7,7 +7,6 @@ import Summary from "@/components/HotelReservation/EnterDetails/Summary"
|
|||||||
import {
|
import {
|
||||||
generateChildrenString,
|
generateChildrenString,
|
||||||
getQueryParamsForEnterDetails,
|
getQueryParamsForEnterDetails,
|
||||||
mapChildrenFromString,
|
|
||||||
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
|
|
||||||
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
@@ -39,27 +38,28 @@ export default async function SummaryPage({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const prices = user && availability.memberRate
|
const prices =
|
||||||
? {
|
user && availability.memberRate
|
||||||
local: {
|
? {
|
||||||
price: availability.memberRate?.localPrice.pricePerStay,
|
local: {
|
||||||
currency: availability.memberRate?.localPrice.currency,
|
price: availability.memberRate?.localPrice.pricePerStay,
|
||||||
},
|
currency: availability.memberRate?.localPrice.currency,
|
||||||
euro: {
|
},
|
||||||
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
euro: {
|
||||||
currency: availability.memberRate?.requestedPrice?.currency,
|
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
||||||
},
|
currency: availability.memberRate?.requestedPrice?.currency,
|
||||||
}
|
},
|
||||||
: {
|
}
|
||||||
local: {
|
: {
|
||||||
price: availability.publicRate?.localPrice.pricePerStay,
|
local: {
|
||||||
currency: availability.publicRate?.localPrice.currency,
|
price: availability.publicRate?.localPrice.pricePerStay,
|
||||||
},
|
currency: availability.publicRate?.localPrice.currency,
|
||||||
euro: {
|
},
|
||||||
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
euro: {
|
||||||
currency: availability.publicRate?.requestedPrice?.currency,
|
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
||||||
},
|
currency: availability.publicRate?.requestedPrice?.currency,
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Summary
|
<Summary
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ export default async function StepPage({
|
|||||||
label={mustBeGuaranteed ? guaranteeWithCard : selectPaymentMethod}
|
label={mustBeGuaranteed ? guaranteeWithCard : selectPaymentMethod}
|
||||||
>
|
>
|
||||||
<Payment
|
<Payment
|
||||||
hotelId={searchParams.hotel}
|
|
||||||
otherPaymentOptions={
|
otherPaymentOptions={
|
||||||
hotelData.data.attributes.merchantInformationData
|
hotelData.data.attributes.merchantInformationData
|
||||||
.alternatePaymentOptions
|
.alternatePaymentOptions
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Counter from "../Counter"
|
|||||||
|
|
||||||
import styles from "./adult-selector.module.css"
|
import styles from "./adult-selector.module.css"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||||
import {
|
import {
|
||||||
AdultSelectorProps,
|
AdultSelectorProps,
|
||||||
Child,
|
Child,
|
||||||
@@ -40,14 +40,14 @@ export default function AdultSelector({ roomIndex = 0 }: AdultSelectorProps) {
|
|||||||
setValue(`rooms.${roomIndex}.adults`, adults - 1)
|
setValue(`rooms.${roomIndex}.adults`, adults - 1)
|
||||||
if (childrenInAdultsBed > adults) {
|
if (childrenInAdultsBed > adults) {
|
||||||
const toUpdateIndex = child.findIndex(
|
const toUpdateIndex = child.findIndex(
|
||||||
(child: Child) => child.bed == BedTypeEnum.IN_ADULTS_BED
|
(child: Child) => child.bed == ChildBedMapEnum.IN_ADULTS_BED
|
||||||
)
|
)
|
||||||
if (toUpdateIndex != -1) {
|
if (toUpdateIndex != -1) {
|
||||||
setValue(
|
setValue(
|
||||||
`rooms.${roomIndex}.children.${toUpdateIndex}.bed`,
|
`rooms.${roomIndex}.children.${toUpdateIndex}.bed`,
|
||||||
child[toUpdateIndex].age < 3
|
child[toUpdateIndex].age < 3
|
||||||
? BedTypeEnum.IN_CRIB
|
? ChildBedMapEnum.IN_CRIB
|
||||||
: BedTypeEnum.IN_EXTRA_BED
|
: ChildBedMapEnum.IN_EXTRA_BED
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|||||||
|
|
||||||
import styles from "./child-selector.module.css"
|
import styles from "./child-selector.module.css"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||||
import {
|
import {
|
||||||
ChildBed,
|
ChildBed,
|
||||||
ChildInfoSelectorProps,
|
ChildInfoSelectorProps,
|
||||||
@@ -59,9 +59,9 @@ export default function ChildInfoSelector({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateSelectedBed(bed: number) {
|
function updateSelectedBed(bed: number) {
|
||||||
if (bed == BedTypeEnum.IN_ADULTS_BED) {
|
if (bed == ChildBedMapEnum.IN_ADULTS_BED) {
|
||||||
increaseChildInAdultsBed(roomIndex)
|
increaseChildInAdultsBed(roomIndex)
|
||||||
} else if (child.bed == BedTypeEnum.IN_ADULTS_BED) {
|
} else if (child.bed == ChildBedMapEnum.IN_ADULTS_BED) {
|
||||||
decreaseChildInAdultsBed(roomIndex)
|
decreaseChildInAdultsBed(roomIndex)
|
||||||
}
|
}
|
||||||
updateChildBed(bed, roomIndex, index)
|
updateChildBed(bed, roomIndex, index)
|
||||||
@@ -71,15 +71,15 @@ export default function ChildInfoSelector({
|
|||||||
const allBedTypes: ChildBed[] = [
|
const allBedTypes: ChildBed[] = [
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: "In adults bed" }),
|
label: intl.formatMessage({ id: "In adults bed" }),
|
||||||
value: BedTypeEnum.IN_ADULTS_BED,
|
value: ChildBedMapEnum.IN_ADULTS_BED,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: "In crib" }),
|
label: intl.formatMessage({ id: "In crib" }),
|
||||||
value: BedTypeEnum.IN_CRIB,
|
value: ChildBedMapEnum.IN_CRIB,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: "In extra bed" }),
|
label: intl.formatMessage({ id: "In extra bed" }),
|
||||||
value: BedTypeEnum.IN_EXTRA_BED,
|
value: ChildBedMapEnum.IN_EXTRA_BED,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||||
|
|
||||||
import { getFormattedUrlQueryParams } from "@/utils/url"
|
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 { BookingData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import type {
|
import type {
|
||||||
@@ -12,13 +14,14 @@ export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
|||||||
return getFormattedUrlQueryParams(searchParams, {
|
return getFormattedUrlQueryParams(searchParams, {
|
||||||
adults: "number",
|
adults: "number",
|
||||||
age: "number",
|
age: "number",
|
||||||
|
bed: ChildBedMapEnum,
|
||||||
}) as SelectRateSearchParams
|
}) as SelectRateSearchParams
|
||||||
}
|
}
|
||||||
|
|
||||||
const bedTypeMap: Record<number, string> = {
|
export const bedTypeMap: Record<number, ChildBedTypeEnum> = {
|
||||||
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
|
[ChildBedMapEnum.IN_ADULTS_BED]: ChildBedTypeEnum.ParentsBed,
|
||||||
[BedTypeEnum.IN_CRIB]: "Crib",
|
[ChildBedMapEnum.IN_CRIB]: ChildBedTypeEnum.Crib,
|
||||||
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
|
[ChildBedMapEnum.IN_EXTRA_BED]: ChildBedTypeEnum.ExtraBed,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateChildrenString(children: Child[]): string {
|
export function generateChildrenString(children: Child[]): string {
|
||||||
@@ -31,17 +34,6 @@ export function generateChildrenString(children: Child[]): string {
|
|||||||
.join(",")}]`
|
.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(
|
export function getQueryParamsForEnterDetails(
|
||||||
searchParams: URLSearchParams
|
searchParams: URLSearchParams
|
||||||
): BookingData {
|
): BookingData {
|
||||||
@@ -49,10 +41,12 @@ export function getQueryParamsForEnterDetails(
|
|||||||
|
|
||||||
const { room } = selectRoomParamsObject
|
const { room } = selectRoomParamsObject
|
||||||
return {
|
return {
|
||||||
...selectRoomParamsObject,
|
fromDate: selectRoomParamsObject.fromDate,
|
||||||
|
toDate: selectRoomParamsObject.toDate,
|
||||||
|
hotel: selectRoomParamsObject.hotel,
|
||||||
rooms: room.map((room) => ({
|
rooms: room.map((room) => ({
|
||||||
adults: room.adults, // TODO: Handle multiple rooms
|
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,
|
roomTypeCode: room.roomtype,
|
||||||
rateCode: room.ratecode,
|
rateCode: room.ratecode,
|
||||||
packages: room.packages?.split(",") as RoomPackageCodeEnum[],
|
packages: room.packages?.split(",") as RoomPackageCodeEnum[],
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export enum BookingStatusEnum {
|
|||||||
PendingPayment = "PendingPayment",
|
PendingPayment = "PendingPayment",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BedTypeEnum {
|
export enum ChildBedTypeEnum {
|
||||||
Crib = "Crib",
|
Crib = "Crib",
|
||||||
ExtraBed = "ExtraBed",
|
ExtraBed = "ExtraBed",
|
||||||
ParentsBed = "ParentsBed",
|
ParentsBed = "ParentsBed",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||||
|
|
||||||
const roomsSchema = z.array(
|
const roomsSchema = z.array(
|
||||||
z.object({
|
z.object({
|
||||||
adults: z.number().int().nonnegative(),
|
adults: z.number().int().nonnegative(),
|
||||||
@@ -7,7 +9,7 @@ const roomsSchema = z.array(
|
|||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
age: z.number().int().nonnegative(),
|
age: z.number().int().nonnegative(),
|
||||||
bedType: z.string(),
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.default([]),
|
.default([]),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/constants/booking"
|
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||||
|
|
||||||
// MUTATION
|
// MUTATION
|
||||||
export const createBookingSchema = z
|
export const createBookingSchema = z
|
||||||
@@ -36,9 +36,9 @@ export const createBookingSchema = z
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// QUERY
|
// QUERY
|
||||||
const childrenAgesSchema = z.object({
|
const extraBedTypesSchema = z.object({
|
||||||
age: z.number(),
|
quantity: z.number(),
|
||||||
bedType: z.nativeEnum(BedTypeEnum),
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
})
|
})
|
||||||
|
|
||||||
const guestSchema = z.object({
|
const guestSchema = z.object({
|
||||||
@@ -65,7 +65,8 @@ export const bookingConfirmationSchema = z
|
|||||||
checkInDate: z.date({ coerce: true }),
|
checkInDate: z.date({ coerce: true }),
|
||||||
checkOutDate: z.date({ coerce: true }),
|
checkOutDate: z.date({ coerce: true }),
|
||||||
createDateTime: 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(),
|
computedReservationStatus: z.string(),
|
||||||
confirmationNumber: z.string(),
|
confirmationNumber: z.string(),
|
||||||
currencyCode: z.string(),
|
currencyCode: z.string(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/constants/booking"
|
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||||
import { dt } from "@/lib/dt"
|
import { dt } from "@/lib/dt"
|
||||||
import { toLang } from "@/server/utils"
|
import { toLang } from "@/server/utils"
|
||||||
|
|
||||||
@@ -441,7 +441,7 @@ export const getHotelDataSchema = z.object({
|
|||||||
|
|
||||||
export const childrenSchema = z.object({
|
export const childrenSchema = z.object({
|
||||||
age: z.number(),
|
age: z.number(),
|
||||||
bedType: z.nativeEnum(BedTypeEnum),
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
})
|
})
|
||||||
|
|
||||||
const occupancySchema = z.object({
|
const occupancySchema = z.object({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { produce } from "immer"
|
|||||||
import { createContext, useContext } from "react"
|
import { createContext, useContext } from "react"
|
||||||
import { create, useStore } from "zustand"
|
import { create, useStore } from "zustand"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||||
import {
|
import {
|
||||||
Child,
|
Child,
|
||||||
GuestsRoom,
|
GuestsRoom,
|
||||||
@@ -41,15 +41,15 @@ export function validateBedTypes(data: extendedGuestsRoom[]) {
|
|||||||
room.child.forEach((child) => {
|
room.child.forEach((child) => {
|
||||||
const allowedBedTypes: number[] = []
|
const allowedBedTypes: number[] = []
|
||||||
if (child.age <= 5 && room.adults >= room.childrenInAdultsBed) {
|
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) {
|
} else if (child.age <= 5) {
|
||||||
room.childrenInAdultsBed = room.childrenInAdultsBed - 1
|
room.childrenInAdultsBed = room.childrenInAdultsBed - 1
|
||||||
}
|
}
|
||||||
if (child.age < 3) {
|
if (child.age < 3) {
|
||||||
allowedBedTypes.push(BedTypeEnum.IN_CRIB)
|
allowedBedTypes.push(ChildBedMapEnum.IN_CRIB)
|
||||||
}
|
}
|
||||||
if (child.age > 2) {
|
if (child.age > 2) {
|
||||||
allowedBedTypes.push(BedTypeEnum.IN_EXTRA_BED)
|
allowedBedTypes.push(ChildBedMapEnum.IN_EXTRA_BED)
|
||||||
}
|
}
|
||||||
if (!allowedBedTypes.includes(child.bed)) {
|
if (!allowedBedTypes.includes(child.bed)) {
|
||||||
child.bed = allowedBedTypes[0]
|
child.bed = allowedBedTypes[0]
|
||||||
@@ -84,7 +84,7 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
|
|||||||
inputData.rooms = initData.map((room) => {
|
inputData.rooms = initData.map((room) => {
|
||||||
const childrenInAdultsBed = room.child
|
const childrenInAdultsBed = room.child
|
||||||
? room.child.reduce((acc, 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
|
return acc
|
||||||
}, 0)
|
}, 0)
|
||||||
: 0
|
: 0
|
||||||
@@ -121,13 +121,13 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
|
|||||||
state.rooms[roomIndex].adults
|
state.rooms[roomIndex].adults
|
||||||
) {
|
) {
|
||||||
const toUpdateIndex = state.rooms[roomIndex].child.findIndex(
|
const toUpdateIndex = state.rooms[roomIndex].child.findIndex(
|
||||||
(child) => child.bed == BedTypeEnum.IN_ADULTS_BED
|
(child) => child.bed == ChildBedMapEnum.IN_ADULTS_BED
|
||||||
)
|
)
|
||||||
if (toUpdateIndex != -1) {
|
if (toUpdateIndex != -1) {
|
||||||
state.rooms[roomIndex].child[toUpdateIndex].bed =
|
state.rooms[roomIndex].child[toUpdateIndex].bed =
|
||||||
state.rooms[roomIndex].child[toUpdateIndex].age < 3
|
state.rooms[roomIndex].child[toUpdateIndex].age < 3
|
||||||
? BedTypeEnum.IN_CRIB
|
? ChildBedMapEnum.IN_CRIB
|
||||||
: BedTypeEnum.IN_EXTRA_BED
|
: ChildBedMapEnum.IN_EXTRA_BED
|
||||||
state.rooms[roomIndex].childrenInAdultsBed =
|
state.rooms[roomIndex].childrenInAdultsBed =
|
||||||
state.rooms[roomIndex].adults
|
state.rooms[roomIndex].adults
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ export function initGuestsRoomsState(initData?: GuestsRoom[]) {
|
|||||||
if (
|
if (
|
||||||
roomChildren.length &&
|
roomChildren.length &&
|
||||||
roomChildren[roomChildren.length - 1].bed ==
|
roomChildren[roomChildren.length - 1].bed ==
|
||||||
BedTypeEnum.IN_ADULTS_BED
|
ChildBedMapEnum.IN_ADULTS_BED
|
||||||
) {
|
) {
|
||||||
state.rooms[roomIndex].childrenInAdultsBed =
|
state.rooms[roomIndex].childrenInAdultsBed =
|
||||||
state.rooms[roomIndex].childrenInAdultsBed - 1
|
state.rooms[roomIndex].childrenInAdultsBed - 1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export enum BedTypeEnum {
|
export enum ChildBedMapEnum {
|
||||||
IN_ADULTS_BED = 0,
|
IN_ADULTS_BED = 0,
|
||||||
IN_CRIB = 1,
|
IN_CRIB = 1,
|
||||||
IN_EXTRA_BED = 2,
|
IN_EXTRA_BED = 2,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
||||||
|
|
||||||
import { BedTypeEnum } from "../../bookingWidget/enums"
|
import { ChildBedMapEnum } from "../../bookingWidget/enums"
|
||||||
|
|
||||||
export interface Child {
|
export interface Child {
|
||||||
bed: BedTypeEnum
|
bed: ChildBedMapEnum
|
||||||
age: number
|
age: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user