fix: rename children to childrenInRoom
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
@@ -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
|
||||
),
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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>({
|
||||
|
||||
@@ -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())],
|
||||
})),
|
||||
|
||||
@@ -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}}",
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user