fix: handle children in enter details
This commit is contained in:
@@ -4,7 +4,11 @@ import {
|
|||||||
} from "@/lib/trpc/memoizedRequests"
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import Summary from "@/components/HotelReservation/EnterDetails/Summary"
|
import Summary from "@/components/HotelReservation/EnterDetails/Summary"
|
||||||
import { getQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import {
|
||||||
|
generateChildrenString,
|
||||||
|
getQueryParamsForEnterDetails,
|
||||||
|
mapChildrenFromString,
|
||||||
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
|
|
||||||
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
||||||
@@ -19,7 +23,7 @@ export default async function SummaryPage({
|
|||||||
const availability = await getSelectedRoomAvailability({
|
const availability = await getSelectedRoomAvailability({
|
||||||
hotelId: hotel,
|
hotelId: hotel,
|
||||||
adults,
|
adults,
|
||||||
children,
|
children: children ? generateChildrenString(children) : undefined,
|
||||||
roomStayStartDate: fromDate,
|
roomStayStartDate: fromDate,
|
||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
@@ -35,25 +39,25 @@ export default async function SummaryPage({
|
|||||||
|
|
||||||
const prices = user
|
const prices = user
|
||||||
? {
|
? {
|
||||||
local: {
|
local: {
|
||||||
price: availability.memberRate?.localPrice.pricePerStay,
|
price: availability.memberRate?.localPrice.pricePerStay,
|
||||||
currency: availability.memberRate?.localPrice.currency,
|
currency: availability.memberRate?.localPrice.currency,
|
||||||
},
|
},
|
||||||
euro: {
|
euro: {
|
||||||
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
price: availability.memberRate?.requestedPrice?.pricePerStay,
|
||||||
currency: availability.memberRate?.requestedPrice?.currency,
|
currency: availability.memberRate?.requestedPrice?.currency,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
local: {
|
local: {
|
||||||
price: availability.publicRate?.localPrice.pricePerStay,
|
price: availability.publicRate?.localPrice.pricePerStay,
|
||||||
currency: availability.publicRate?.localPrice.currency,
|
currency: availability.publicRate?.localPrice.currency,
|
||||||
},
|
},
|
||||||
euro: {
|
euro: {
|
||||||
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
price: availability.publicRate?.requestedPrice?.pricePerStay,
|
||||||
currency: availability.publicRate?.requestedPrice?.currency,
|
currency: availability.publicRate?.requestedPrice?.currency,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Summary
|
<Summary
|
||||||
@@ -63,6 +67,7 @@ export default async function SummaryPage({
|
|||||||
localPrice: prices.local,
|
localPrice: prices.local,
|
||||||
euroPrice: prices.euro,
|
euroPrice: prices.euro,
|
||||||
adults,
|
adults,
|
||||||
|
children,
|
||||||
cancellationText: availability.cancellationText,
|
cancellationText: availability.cancellationText,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ import Details from "@/components/HotelReservation/EnterDetails/Details"
|
|||||||
import HistoryStateManager from "@/components/HotelReservation/EnterDetails/HistoryStateManager"
|
import HistoryStateManager from "@/components/HotelReservation/EnterDetails/HistoryStateManager"
|
||||||
import Payment from "@/components/HotelReservation/EnterDetails/Payment"
|
import Payment from "@/components/HotelReservation/EnterDetails/Payment"
|
||||||
import SectionAccordion from "@/components/HotelReservation/EnterDetails/SectionAccordion"
|
import SectionAccordion from "@/components/HotelReservation/EnterDetails/SectionAccordion"
|
||||||
import { getQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import {
|
||||||
|
generateChildrenString,
|
||||||
|
getQueryParamsForEnterDetails,
|
||||||
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
|
||||||
import { StepEnum } from "@/types/components/hotelReservation/enterDetails/step"
|
import { StepEnum } from "@/types/components/hotelReservation/enterDetails/step"
|
||||||
@@ -49,12 +52,14 @@ export default async function StepPage({
|
|||||||
toDate,
|
toDate,
|
||||||
} = getQueryParamsForEnterDetails(selectRoomParams)
|
} = getQueryParamsForEnterDetails(selectRoomParams)
|
||||||
|
|
||||||
|
const childrenAsString = children && generateChildrenString(children)
|
||||||
|
|
||||||
const breakfastInput = { adults, fromDate, hotelId, toDate }
|
const breakfastInput = { adults, fromDate, hotelId, toDate }
|
||||||
void getBreakfastPackages(breakfastInput)
|
void getBreakfastPackages(breakfastInput)
|
||||||
void getSelectedRoomAvailability({
|
void getSelectedRoomAvailability({
|
||||||
hotelId,
|
hotelId,
|
||||||
adults,
|
adults,
|
||||||
children,
|
children: childrenAsString,
|
||||||
roomStayStartDate: fromDate,
|
roomStayStartDate: fromDate,
|
||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
@@ -69,7 +74,7 @@ export default async function StepPage({
|
|||||||
const roomAvailability = await getSelectedRoomAvailability({
|
const roomAvailability = await getSelectedRoomAvailability({
|
||||||
hotelId,
|
hotelId,
|
||||||
adults,
|
adults,
|
||||||
children,
|
children: childrenAsString,
|
||||||
roomStayStartDate: fromDate,
|
roomStayStartDate: fromDate,
|
||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import { getLocations } from "@/lib/trpc/memoizedRequests"
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
fetchAvailableHotels,
|
fetchAvailableHotels,
|
||||||
generateChildrenString,
|
|
||||||
getFiltersFromHotels,
|
getFiltersFromHotels,
|
||||||
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
||||||
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
|
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
|
||||||
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
|
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
|
||||||
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import {
|
||||||
|
generateChildrenString,
|
||||||
|
getHotelReservationQueryParams,
|
||||||
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { ChevronRightIcon } from "@/components/Icons"
|
import { ChevronRightIcon } from "@/components/Icons"
|
||||||
import StaticMap from "@/components/Maps/StaticMap"
|
import StaticMap from "@/components/Maps/StaticMap"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import { serverClient } from "@/lib/trpc/server"
|
|||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
|
||||||
import { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
import { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
||||||
import { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
import { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
||||||
import { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
import { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||||
import { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
||||||
|
|
||||||
export async function fetchAvailableHotels(
|
export async function fetchAvailableHotels(
|
||||||
input: AvailabilityInput
|
input: AvailabilityInput
|
||||||
@@ -43,19 +41,3 @@ export function getFiltersFromHotels(hotels: HotelData[]) {
|
|||||||
|
|
||||||
return filterList
|
return filterList
|
||||||
}
|
}
|
||||||
|
|
||||||
const bedTypeMap: Record<number, string> = {
|
|
||||||
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
|
|
||||||
[BedTypeEnum.IN_CRIB]: "Crib",
|
|
||||||
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateChildrenString(children: Child[]): string {
|
|
||||||
return `[${children
|
|
||||||
?.map((child) => {
|
|
||||||
const age = child.age
|
|
||||||
const bedType = bedTypeMap[+child.bed]
|
|
||||||
return `${age}:${bedType}`
|
|
||||||
})
|
|
||||||
.join(",")}]`
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import { HotelIncludeEnum } from "@/server/routers/hotels/input"
|
|||||||
|
|
||||||
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
||||||
import Rooms from "@/components/HotelReservation/SelectRate/Rooms"
|
import Rooms from "@/components/HotelReservation/SelectRate/Rooms"
|
||||||
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import {
|
||||||
|
generateChildrenString,
|
||||||
|
getHotelReservationQueryParams,
|
||||||
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import { generateChildrenString } from "../select-hotel/utils"
|
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
import { LangParams, PageArgs } from "@/types/params"
|
import { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { getFormattedUrlQueryParams } from "@/utils/url"
|
import { getFormattedUrlQueryParams } from "@/utils/url"
|
||||||
|
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
||||||
|
import type {
|
||||||
|
Child,
|
||||||
|
SelectRateSearchParams,
|
||||||
|
} from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
|
|
||||||
export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
||||||
return getFormattedUrlQueryParams(searchParams, {
|
return getFormattedUrlQueryParams(searchParams, {
|
||||||
@@ -9,6 +13,33 @@ export function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
|||||||
}) as SelectRateSearchParams
|
}) as SelectRateSearchParams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bedTypeMap: Record<number, string> = {
|
||||||
|
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
|
||||||
|
[BedTypeEnum.IN_CRIB]: "Crib",
|
||||||
|
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateChildrenString(children: Child[]): string {
|
||||||
|
return `[${children
|
||||||
|
.map((child) => {
|
||||||
|
const age = child.age
|
||||||
|
const bedType = bedTypeMap[parseInt(child.bed.toString())]
|
||||||
|
return `${age}:${bedType}`
|
||||||
|
})
|
||||||
|
.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) {
|
export function getQueryParamsForEnterDetails(searchParams: URLSearchParams) {
|
||||||
const selectRoomParamsObject = getHotelReservationQueryParams(searchParams)
|
const selectRoomParamsObject = getHotelReservationQueryParams(searchParams)
|
||||||
|
|
||||||
@@ -16,7 +47,7 @@ export function getQueryParamsForEnterDetails(searchParams: URLSearchParams) {
|
|||||||
return {
|
return {
|
||||||
...selectRoomParamsObject,
|
...selectRoomParamsObject,
|
||||||
adults: room[0].adults, // TODO: Handle multiple rooms
|
adults: room[0].adults, // TODO: Handle multiple rooms
|
||||||
children: room[0].child?.length.toString(), // TODO: Handle multiple rooms and children
|
children: room[0].child, // TODO: Handle multiple rooms and children
|
||||||
roomTypeCode: room[0].roomtype,
|
roomTypeCode: room[0].roomtype,
|
||||||
rateCode: room[0].ratecode,
|
rateCode: room[0].ratecode,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { BedTypeEnum } from "../../bookingWidget/enums"
|
||||||
|
|
||||||
interface Child {
|
interface Child {
|
||||||
bed: string
|
bed: BedTypeEnum
|
||||||
age: number
|
age: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
||||||
|
|
||||||
|
import { BedTypeEnum } from "../../bookingWidget/enums"
|
||||||
|
|
||||||
export interface Child {
|
export interface Child {
|
||||||
bed: string
|
bed: BedTypeEnum
|
||||||
age: number
|
age: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user