fix: rename children to childrenInRoom

This commit is contained in:
Christel Westerberg
2025-01-14 12:25:17 +01:00
parent b2935114e3
commit bcae63e3fc
26 changed files with 104 additions and 91 deletions

View File

@@ -23,8 +23,8 @@ export default async function SelectHotelMapPage({
const {
city,
adultsInRoom,
childrenInRoomString,
childrenInRoom,
childrenInRoomArray,
selectHotelParams,
} = searchDetails
@@ -41,8 +41,8 @@ export default async function SelectHotelMapPage({
city={city}
selectHotelParams={selectHotelParams}
adultsInRoom={adultsInRoom}
childrenInRoomString={childrenInRoomString}
childrenInRoom={childrenInRoom}
child={childrenInRoomArray}
/>
</Suspense>
</MapContainer>

View File

@@ -21,8 +21,8 @@ export default async function SelectHotelPage({
city,
selectHotelParams,
adultsInRoom,
childrenInRoomString,
childrenInRoom,
childrenInRoomArray,
} = searchDetails
if (!city) return notFound()
@@ -30,13 +30,13 @@ export default async function SelectHotelPage({
const reservationParams = {
selectHotelParams,
adultsInRoom,
childrenInRoomString,
childrenInRoom,
childrenInRoomArray,
}
return (
<Suspense
key={`${city.name}-${searchParams.fromDate}-${searchParams.toDate}-${adultsInRoom}-${childrenInRoom}`}
key={`${city.name}-${searchParams.fromDate}-${searchParams.toDate}-${adultsInRoom}-${childrenInRoomString}`}
fallback={<SelectHotelSkeleton />}
>
<SelectHotel

View File

@@ -29,7 +29,7 @@ export default async function SelectRatePage({
setLang(params.lang)
const searchDetails = await getHotelSearchDetails({ searchParams })
if (!searchDetails) return notFound()
const { hotel, adultsInRoom, childrenInRoomArray, selectHotelParams } =
const { hotel, adultsInRoom, childrenInRoom, selectHotelParams } =
searchDetails
if (!hotel) return notFound()
@@ -62,9 +62,9 @@ export default async function SelectRatePage({
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
departureDate: format(departureDate, "yyyy-MM-dd"),
noOfAdults: adultsInRoom,
noOfChildren: childrenInRoomArray?.length,
ageOfChildren: childrenInRoomArray?.map((c) => c.age).join(","),
childBedPreference: childrenInRoomArray
noOfChildren: childrenInRoom?.length,
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
childBedPreference: childrenInRoom
?.map((c) => ChildBedMapEnum[c.bed])
.join("|"),
noOfRooms: 1, // // TODO: Handle multiple rooms
@@ -88,7 +88,7 @@ export default async function SelectRatePage({
fromDate={fromDate.toDate()}
toDate={toDate.toDate()}
adultCount={adultsInRoom}
childArray={childrenInRoomArray}
childArray={childrenInRoom}
/>
<Suspense key={hotelId} fallback={<RoomsContainerSkeleton />}>
@@ -98,7 +98,7 @@ export default async function SelectRatePage({
fromDate={fromDate.toDate()}
toDate={toDate.toDate()}
adultCount={adultsInRoom}
childArray={childrenInRoomArray}
childArray={childrenInRoom}
/>
</Suspense>
<Suspense fallback={null}>

View File

@@ -64,13 +64,20 @@ export default async function StepPage({
const {
hotelId,
rooms: [
{ adults, children, roomTypeCode, rateCode, packages: packageCodes },
{
adults,
childrenInRoom,
roomTypeCode,
rateCode,
packages: packageCodes,
},
], // TODO: Handle multiple rooms
fromDate,
toDate,
} = booking
const childrenAsString = children && generateChildrenString(children)
const childrenAsString =
childrenInRoom && generateChildrenString(childrenInRoom)
const breakfastInput = { adults, fromDate, hotelId, toDate }
const selectedRoomAvailabilityInput = {
adults,
@@ -89,7 +96,7 @@ export default async function StepPage({
if (packageCodes?.length) {
void getPackages({
adults,
children: children?.length,
children: childrenInRoom?.length,
endDate: toDate,
hotelId,
packageCodes,
@@ -100,7 +107,7 @@ export default async function StepPage({
const packages = packageCodes
? await getPackages({
adults,
children: children?.length,
children: childrenInRoom?.length,
endDate: toDate,
hotelId,
packageCodes,
@@ -170,9 +177,11 @@ export default async function StepPage({
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
departureDate: format(departureDate, "yyyy-MM-dd"),
noOfAdults: adults,
noOfChildren: children?.length,
ageOfChildren: children?.map((c) => c.age).join(","),
childBedPreference: children?.map((c) => ChildBedMapEnum[c.bed]).join("|"),
noOfChildren: childrenInRoom?.length,
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
childBedPreference: childrenInRoom
?.map((c) => ChildBedMapEnum[c.bed])
.join("|"),
noOfRooms: 1, // // TODO: Handle multiple rooms
duration: differenceInCalendarDays(departureDate, arrivalDate),
leadTime: differenceInCalendarDays(arrivalDate, new Date()),

View File

@@ -17,8 +17,8 @@ interface HotelSearchDetails<T> {
hotel: Location | null
selectHotelParams: T
adultsInRoom: number
childrenInRoom?: string
childrenInRoomArray?: Child[]
childrenInRoomString?: string
childrenInRoom?: Child[]
}
export async function getHotelSearchDetails<
@@ -48,17 +48,18 @@ export async function getHotelSearchDetails<
if (!city && !hotel) return notFound()
let adultsInRoom = 1
let childrenInRoom: string | undefined = undefined
let childrenInRoomArray: Child[] | undefined = undefined
let childrenInRoomString: HotelSearchDetails<T>["childrenInRoomString"] =
undefined
let childrenInRoom: HotelSearchDetails<T>["childrenInRoom"] = undefined
const { rooms } = selectHotelParams
if (rooms && rooms.length > 0) {
adultsInRoom = rooms[0].adults // TODO: Handle multiple rooms
childrenInRoom = rooms[0].children
? generateChildrenString(rooms[0].children)
childrenInRoomString = rooms[0].childrenInRoom
? generateChildrenString(rooms[0].childrenInRoom)
: undefined // TODO: Handle multiple rooms
childrenInRoomArray = rooms[0].children ? rooms[0].children : undefined // TODO: Handle multiple rooms
childrenInRoom = rooms[0].childrenInRoom // TODO: Handle multiple rooms
}
return {
@@ -66,7 +67,7 @@ export async function getHotelSearchDetails<
hotel: hotel ?? null,
selectHotelParams,
adultsInRoom,
childrenInRoomString,
childrenInRoom,
childrenInRoomArray,
}
}

View File

@@ -82,15 +82,16 @@ export default function BookingWidgetClient({
)
: undefined
const defaultRoomsData = bookingWidgetSearchData?.rooms?.map((room) => ({
adults: room.adults,
children: room.children ?? [],
})) ?? [
{
adults: 1,
children: [],
},
]
const defaultRoomsData: BookingWidgetSchema["rooms"] =
bookingWidgetSearchData?.rooms?.map((room) => ({
adults: room.adults,
childrenInRoom: room.childrenInRoom ?? [],
})) ?? [
{
adults: 1,
childrenInRoom: [],
},
]
const methods = useForm<BookingWidgetSchema>({
defaultValues: {

View File

@@ -49,8 +49,8 @@ export default function MobileToggleButton({
return acc
}, 0)
const totalChildren = rooms.reduce((acc, room) => {
if (room.children) {
acc = acc + room.children.length
if (room.childrenInRoom) {
acc = acc + room.childrenInRoom.length
}
return acc
}, 0)

View File

@@ -6,7 +6,7 @@ import type { Location } from "@/types/trpc/routers/hotel/locations"
export const guestRoomSchema = z
.object({
adults: z.number().default(1),
children: z
childrenInRoom: z
.array(
z.object({
age: z.number().min(0, "Age is required"),
@@ -16,11 +16,11 @@ export const guestRoomSchema = z
.default([]),
})
.superRefine((value, ctx) => {
const childrenInAdultsBed = value.children.filter(
const childrenInAdultsBed = value.childrenInRoom.filter(
(c) => c.bed === ChildBedMapEnum.IN_ADULTS_BED
)
if (value.adults < childrenInAdultsBed.length) {
const lastAdultBedIndex = value.children
const lastAdultBedIndex = value.childrenInRoom
.map((c) => c.bed)
.lastIndexOf(ChildBedMapEnum.IN_ADULTS_BED)
@@ -28,7 +28,7 @@ export const guestRoomSchema = z
code: z.ZodIssueCode.custom,
message:
"You cannot have more children in adults bed than adults in the room",
path: ["child", lastAdultBedIndex],
path: ["childrenInRoom", lastAdultBedIndex],
})
}
})

View File

@@ -29,8 +29,8 @@ export default function ChildInfoSelector({
index = 0,
roomIndex = 0,
}: ChildInfoSelectorProps) {
const ageFieldName = `rooms.${roomIndex}.children.${index}.age`
const bedFieldName = `rooms.${roomIndex}.children.${index}.bed`
const ageFieldName = `rooms.${roomIndex}.childrenInRoom.${index}.age`
const bedFieldName = `rooms.${roomIndex}.childrenInRoom.${index}.bed`
const intl = useIntl()
const ageLabel = intl.formatMessage({ id: "Age" })
const bedLabel = intl.formatMessage({ id: "Bed" })
@@ -38,11 +38,11 @@ export default function ChildInfoSelector({
const { setValue, formState } = useFormContext()
function updateSelectedBed(bed: number) {
setValue(`rooms.${roomIndex}.children.${index}.bed`, bed)
setValue(`rooms.${roomIndex}.childrenInRoom.${index}.bed`, bed)
}
function updateSelectedAge(age: number) {
setValue(`rooms.${roomIndex}.children.${index}.age`, age)
setValue(`rooms.${roomIndex}.childrenInRoom.${index}.age`, age)
const availableBedTypes = getAvailableBeds(age)
updateSelectedBed(availableBedTypes[0].value)
}
@@ -76,8 +76,9 @@ export default function ChildInfoSelector({
return availableBedTypes
}
//@ts-expect-error: formState is typed with FormValues
const roomErrors = formState.errors.rooms?.[roomIndex]?.children?.[index]
const roomErrors =
//@ts-expect-error: formState is typed with FormValues
formState.errors.rooms?.[roomIndex]?.childrenInRoom?.[index]
const ageError = roomErrors?.age
const bedError = roomErrors?.bed

View File

@@ -24,7 +24,7 @@ export default function ChildSelector({
function increaseChildrenCount(roomIndex: number) {
if (currentChildren.length < 5) {
setValue(`rooms.${roomIndex}.children.${currentChildren.length}`, {
setValue(`rooms.${roomIndex}.childrenInRoom.${currentChildren.length}`, {
age: undefined,
bed: undefined,
})
@@ -33,7 +33,7 @@ export default function ChildSelector({
function decreaseChildrenCount(roomIndex: number) {
if (currentChildren.length > 0) {
currentChildren.pop()
setValue(`rooms.${roomIndex}.children`, currentChildren)
setValue(`rooms.${roomIndex}.childrenInRoom`, currentChildren)
}
}

View File

@@ -48,7 +48,7 @@ export default function GuestsRoomsPickerDialog({
}, [trigger, onClose])
const handleAddRoom = useCallback(() => {
setValue("rooms", [...roomsValue, { adults: 1, children: [] }], {
setValue("rooms", [...roomsValue, { adults: 1, childrenInRoom: [] }], {
shouldValidate: true,
})
}, [roomsValue, setValue])

View File

@@ -25,7 +25,7 @@ export function GuestsRoom({
const intl = useIntl()
const roomLabel = intl.formatMessage({ id: "Room" })
const childrenInAdultsBed = room.children.filter(
const childrenInAdultsBed = room.childrenInRoom.filter(
(child) => child.bed === ChildBedMapEnum.IN_ADULTS_BED
).length
@@ -38,13 +38,13 @@ export function GuestsRoom({
<AdultSelector
roomIndex={index}
currentAdults={room.adults}
currentChildren={room.children}
currentChildren={room.childrenInRoom}
childrenInAdultsBed={childrenInAdultsBed}
/>
<ChildSelector
roomIndex={index}
currentAdults={room.adults}
currentChildren={room.children}
currentChildren={room.childrenInRoom}
childrenInAdultsBed={childrenInAdultsBed}
/>
{index !== 0 && (

View File

@@ -29,7 +29,7 @@ export default function GuestsRoomsPickerForm() {
const [isOpen, setIsOpen] = useState(false)
const [containerHeight, setContainerHeight] = useState(0)
const childCount =
rooms[0] && rooms[0].children ? rooms[0].children.length : 0 // ToDo Update for multiroom later
rooms[0] && rooms[0].childrenInRoom ? rooms[0].childrenInRoom.length : 0 // ToDo Update for multiroom later
const htmlElement =
typeof window !== "undefined" ? document.querySelector("body") : null
@@ -154,7 +154,7 @@ function Trigger({
)
)
if (rooms.some((room) => room.children.length > 0)) {
if (rooms.some((room) => room.childrenInRoom.length > 0)) {
parts.push(
intl.formatMessage(
{
@@ -162,7 +162,7 @@ function Trigger({
},
{
totalChildren: rooms.reduce(
(acc, room) => acc + room.children.length,
(acc, room) => acc + room.childrenInRoom.length,
0
),
}

View File

@@ -11,7 +11,7 @@ export default function BedTypeInfo({ hasMultipleBedTypes }: BedTypeInfoProps) {
const intl = useIntl()
const hasChildWithExtraBed = useEnterDetailsStore((state) =>
state.booking.rooms[0].children?.some(
state.booking.rooms[0].childrenInRoom?.some(
(child) => Number(child.bed) === ChildBedMapEnum.IN_EXTRA_BED
)
)

View File

@@ -38,7 +38,7 @@ export default function Breakfast({ packages }: BreakfastProps) {
)
const children = useEnterDetailsStore(
(state) => state.booking.rooms[0].children
(state) => state.booking.rooms[0].childrenInRoom
)
const methods = useForm<BreakfastFormSchema>({

View File

@@ -239,7 +239,7 @@ export default function PaymentClient({
checkOutDate: toDate,
rooms: rooms.map((room) => ({
adults: room.adults,
childrenAges: room.children?.map((child) => ({
childrenAges: room.childrenInRoom?.map((child) => ({
age: child.age,
bedType: bedTypeMap[parseInt(child.bed.toString())],
})),

View File

@@ -66,7 +66,7 @@ export default function PriceDetailsTable({
useEnterDetailsStore(storeSelector)
// TODO: Update for Multiroom later
const { adults, children } = booking.rooms[0]
const { adults, childrenInRoom } = booking.rooms[0]
const nights = getNights(booking.fromDate, booking.toDate)
const vatPercentage = vat / 100
@@ -121,13 +121,13 @@ export default function PriceDetailsTable({
breakfast.localPrice.currency
)}
/>
{children?.length ? (
{childrenInRoom?.length ? (
<Row
label={`${intl.formatMessage(
{
id: "{totalChildren, plural, one {# child} other {# children}}",
},
{ totalChildren: children.length }
{ totalChildren: childrenInRoom.length }
)}, ${intl.formatMessage(
{
id: "{totalBreakfasts, plural, one {# breakfast} other {# breakfasts}}",

View File

@@ -73,7 +73,7 @@ export default function SummaryUI({
// TODO: Update for Multiroom later
const adults = booking.rooms[0].adults
const children = booking.rooms[0].children
const children = booking.rooms[0].childrenInRoom
const childrenBeds = children?.reduce(
(acc, value) => {

View File

@@ -26,7 +26,6 @@ import {
type TrackingSDKHotelInfo,
type TrackingSDKPageData,
} from "@/types/components/tracking"
import type { Lang } from "@/constants/languages"
function isValidHotelData(hotel: NullableHotelData): hotel is HotelData {
return hotel !== null && hotel !== undefined
@@ -37,7 +36,7 @@ export async function SelectHotelMapContainer({
selectHotelParams,
adultsInRoom,
childrenInRoom,
child,
childrenInRoomString,
}: SelectHotelMapContainerProps) {
const lang = getLang()
const googleMapId = env.GOOGLE_DYNAMIC_MAP_ID
@@ -49,7 +48,7 @@ export async function SelectHotelMapContainer({
roomStayStartDate: selectHotelParams.fromDate,
roomStayEndDate: selectHotelParams.toDate,
adults: adultsInRoom,
children: childrenInRoom,
children: childrenInRoomString,
})
)
@@ -83,9 +82,11 @@ export async function SelectHotelMapContainer({
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
departureDate: format(departureDate, "yyyy-MM-dd"),
noOfAdults: adultsInRoom,
noOfChildren: child?.length,
ageOfChildren: child?.map((c) => c.age).join(","),
childBedPreference: child?.map((c) => ChildBedMapEnum[c.bed]).join("|"),
noOfChildren: childrenInRoom?.length,
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
childBedPreference: childrenInRoom
?.map((c) => ChildBedMapEnum[c.bed])
.join("|"),
noOfRooms: 1, // // TODO: Handle multiple rooms
duration: differenceInCalendarDays(departureDate, arrivalDate),
leadTime: differenceInCalendarDays(arrivalDate, new Date()),

View File

@@ -48,8 +48,8 @@ export default async function SelectHotel({
const {
selectHotelParams,
adultsInRoom,
childrenInRoomString,
childrenInRoom,
childrenInRoomArray,
} = reservationParams
const intl = await getIntl()
@@ -60,7 +60,7 @@ export default async function SelectHotel({
roomStayStartDate: selectHotelParams.fromDate,
roomStayEndDate: selectHotelParams.toDate,
adults: adultsInRoom,
children: childrenInRoom,
children: childrenInRoomString,
})
)
@@ -118,9 +118,9 @@ export default async function SelectHotel({
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
departureDate: format(departureDate, "yyyy-MM-dd"),
noOfAdults: adultsInRoom,
noOfChildren: childrenInRoomArray?.length,
ageOfChildren: childrenInRoomArray?.map((c) => c.age).join(","),
childBedPreference: childrenInRoomArray
noOfChildren: childrenInRoom?.length,
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
childBedPreference: childrenInRoom
?.map((c) => ChildBedMapEnum[c.bed])
.join("|"),
noOfRooms: 1, // // TODO: Handle multiple rooms

View File

@@ -5,7 +5,7 @@ export type ChildBed = {
value: number
}
export type TGuestsRoom = Required<Pick<Room, "adults" | "children">>
export type TGuestsRoom = Required<Pick<Room, "adults" | "childrenInRoom">>
export type GuestsRoomPickerProps = {
index: number

View File

@@ -68,6 +68,6 @@ export type SelectHotelMapContainerProps = {
city: Location
selectHotelParams: SelectHotelSearchParams
adultsInRoom: number
childrenInRoom: string | undefined
child: Child[] | undefined
childrenInRoomString: string | undefined
childrenInRoom: Child[] | undefined
}

View File

@@ -48,7 +48,7 @@ export interface SelectHotelProps {
reservationParams: {
selectHotelParams: SelectHotelSearchParams
adultsInRoom: number
childrenInRoom: string | undefined
childrenInRoomArray: Child[] | undefined
childrenInRoomString: string | undefined
childrenInRoom: Child[] | undefined
}
}

View File

@@ -4,6 +4,6 @@ export interface SelectHotelSearchParams {
city: string
fromDate: string
toDate: string
rooms: Pick<Room, "adults" | "children">[]
[key: string]: string | string[] | Pick<Room, "adults" | "children">[]
rooms: Pick<Room, "adults" | "childrenInRoom">[]
[key: string]: string | string[] | Pick<Room, "adults" | "childrenInRoom">[]
}

View File

@@ -12,7 +12,7 @@ export interface Room {
roomTypeCode: string
rateCode: string
counterRateCode: string
children?: Child[]
childrenInRoom?: Child[]
packages?: RoomPackageCodeEnum[]
}

View File

@@ -26,7 +26,7 @@ const keyedSearchParams = new Map([
["fromdate", "fromDate"],
["todate", "toDate"],
["hotel", "hotelId"],
["child", "children"],
["child", "childrenInRoom"],
])
export function getKeyFromSearchParam(key: string): string {
@@ -71,19 +71,19 @@ export function convertSearchParamsToObj<T extends PartialRoom>(
roomObject[index].adults = Number(value)
// Child is an array, so we need to handle it separately
} else if (roomObjectKey === "children") {
} else if (roomObjectKey === "childrenInRoom") {
const childIndex = Number(keys[3])
const childKey = keys[4] as keyof Child
if (
!("children" in roomObject[index]) ||
!Array.isArray(roomObject[index].children)
!("childrenInRoom" in roomObject[index]) ||
!Array.isArray(roomObject[index].childrenInRoom)
) {
roomObject[index].children = []
roomObject[index].childrenInRoom = []
}
roomObject[index].children![childIndex] = {
...roomObject[index].children![childIndex],
roomObject[index].childrenInRoom![childIndex] = {
...roomObject[index].childrenInRoom![childIndex],
[childKey]: Number(value),
}
} else if (roomObjectKey === "packages") {
@@ -115,8 +115,8 @@ export function convertObjToSearchParams<T>(
item.adults.toString()
)
}
if (item?.children) {
item.children.forEach((child, childIndex) => {
if (item?.childrenInRoom) {
item.childrenInRoom.forEach((child, childIndex) => {
bookingSearchParams.set(
`room[${index}].child[${childIndex}].age`,
child.age.toString()