diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx index fdd5436f3..a9103d2c4 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx @@ -2,6 +2,7 @@ import { getProfileSafely } from "@/lib/trpc/memoizedRequests" import { serverClient } from "@/lib/trpc/server" import RoomSelection from "@/components/HotelReservation/SelectRate/RoomSelection" +import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils" import { setLang } from "@/i18n/serverContext" import styles from "./page.module.css" @@ -15,6 +16,12 @@ export default async function SelectRatePage({ }: PageArgs) { setLang(params.lang) + const selecetRoomParams = new URLSearchParams(searchParams) + const selecetRoomParamsObject = + getHotelReservationQueryParams(selecetRoomParams) + const adults = selecetRoomParamsObject.room[0].adults // TODO: Handle multiple rooms + const children = selecetRoomParamsObject.room[0].child.length // TODO: Handle multiple rooms + const [hotelData, roomConfigurations, user] = await Promise.all([ serverClient().hotel.hotelData.get({ hotelId: searchParams.hotel, @@ -23,9 +30,10 @@ export default async function SelectRatePage({ }), serverClient().hotel.availability.rooms({ hotelId: parseInt(searchParams.hotel, 10), - roomStayStartDate: "2024-11-02", - roomStayEndDate: "2024-11-03", - adults: 1, + roomStayStartDate: searchParams.fromDate, + roomStayEndDate: searchParams.toDate, + adults: adults, + children: children, }), getProfileSafely(), ]) diff --git a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx index 3086a5c2b..a523305ae 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/index.tsx @@ -18,6 +18,7 @@ export default function FlexibilityOption({ paymentTerm, priceInformation, roomType, + roomTypeCode, handleSelectRate, }: FlexibilityOptionProps) { const [rootDiv, setRootDiv] = useState(undefined) @@ -46,7 +47,8 @@ export default function FlexibilityOption({ function onChange() { const rate = { - roomType: roomType, + roomTypeCode, + roomType, priceName: name, public: publicPrice, member: memberPrice, diff --git a/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx index 29d4b0740..b929bfe76 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx @@ -24,17 +24,15 @@ export default function RateSummary({
- <> - - {priceToShow?.localPrice.pricePerStay}{" "} - {priceToShow?.localPrice.currency} - - - {intl.formatMessage({ id: "Approx." })}{" "} - {priceToShow?.requestedPrice?.pricePerStay}{" "} - {priceToShow?.requestedPrice?.currency} - - + + {priceToShow?.localPrice.pricePerStay}{" "} + {priceToShow?.localPrice.currency} + + + {intl.formatMessage({ id: "Approx." })}{" "} + {priceToShow?.requestedPrice?.pricePerStay}{" "} + {priceToShow?.requestedPrice?.currency} +
diff --git a/components/HotelReservation/SelectRate/RoomSelection/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/index.tsx index 7d1c15d6d..c4c5e2e87 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/index.tsx @@ -4,6 +4,7 @@ import { useState } from "react" import RateSummary from "./RateSummary" import RoomCard from "./RoomCard" +import getHotelReservationQueryParams from "./utils" import styles from "./roomSelection.module.css" @@ -19,12 +20,29 @@ export default function RoomSelection({ const router = useRouter() const searchParams = useSearchParams() + const isUserLoggedIn = !!user function handleSubmit(e: React.FormEvent) { e.preventDefault() + const searchParamsObject = getHotelReservationQueryParams(searchParams) + const queryParams = new URLSearchParams(searchParams) - queryParams.set("roomClass", e.currentTarget.roomClass?.value) - queryParams.set("flexibility", e.currentTarget.flexibility?.value) + + searchParamsObject.room.forEach((item, index) => { + if (rateSummary?.roomTypeCode) { + queryParams.set(`room[${index}].roomtype`, rateSummary.roomTypeCode) + } + if (rateSummary?.public?.rateCode) { + queryParams.set(`room[${index}].ratecode`, rateSummary.public.rateCode) + } + if (rateSummary?.member?.rateCode) { + queryParams.set( + `room[${index}].counterratecode`, + rateSummary.member.rateCode + ) + } + }) + router.push(`select-bed?${queryParams}`) } @@ -48,7 +66,10 @@ export default function RoomSelection({ ))} {rateSummary && ( - + )} diff --git a/components/HotelReservation/SelectRate/RoomSelection/utils.ts b/components/HotelReservation/SelectRate/RoomSelection/utils.ts new file mode 100644 index 000000000..e47a0da70 --- /dev/null +++ b/components/HotelReservation/SelectRate/RoomSelection/utils.ts @@ -0,0 +1,28 @@ +import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" + +function getHotelReservationQueryParams(searchParams: URLSearchParams) { + const searchParamsObject: Record = Array.from( + searchParams.entries() + ).reduce>( + (acc, [key, value]) => { + const keys = key.replace(/\]/g, "").split(/\[|\./) // Split keys by '[' or '.' + keys.reduce((nestedAcc, k, i) => { + if (i === keys.length - 1) { + // Convert value to number if the key is 'adults' or 'age' + ;(nestedAcc as Record)[k] = + k === "adults" || k === "age" ? Number(value) : value + } else { + if (!nestedAcc[k]) { + nestedAcc[k] = isNaN(Number(keys[i + 1])) ? {} : [] // Initialize as object or array + } + } + return nestedAcc[k] as Record + }, acc) + return acc + }, + {} as Record + ) + return searchParamsObject as SelectRateSearchParams +} + +export default getHotelReservationQueryParams diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 1839f26a5..4b3f1a84e 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -269,6 +269,8 @@ export const hotelQueryRouter = router({ hotels: serviceProcedure .input(getHotelsAvailabilityInputSchema) .query(async ({ input, ctx }) => { + const { lang } = ctx + const apiLang = toApiLang(lang) const { cityId, roomStayStartDate, @@ -288,6 +290,7 @@ export const hotelQueryRouter = router({ promotionCode, reservationProfileType, attachedProfileId, + language: apiLang, } hotelsAvailabilityCounter.add(1, { diff --git a/types/components/hotelReservation/selectRate/flexibilityOption.ts b/types/components/hotelReservation/selectRate/flexibilityOption.ts index 473de563b..1835c3b65 100644 --- a/types/components/hotelReservation/selectRate/flexibilityOption.ts +++ b/types/components/hotelReservation/selectRate/flexibilityOption.ts @@ -1,6 +1,10 @@ import { z } from "zod" -import { Product, productTypePriceSchema } from "@/server/routers/hotels/output" +import { + Product, + productTypePriceSchema, + RoomConfiguration, +} from "@/server/routers/hotels/output" import { Rate } from "./selectRate" @@ -12,7 +16,8 @@ export type FlexibilityOptionProps = { value: string paymentTerm: string priceInformation?: Array - roomType: string + roomType: RoomConfiguration["roomType"] + roomTypeCode: RoomConfiguration["roomTypeCode"] handleSelectRate: (rate: Rate) => void } diff --git a/types/components/hotelReservation/selectRate/selectRate.ts b/types/components/hotelReservation/selectRate/selectRate.ts index 43152f11b..58aa6fbbe 100644 --- a/types/components/hotelReservation/selectRate/selectRate.ts +++ b/types/components/hotelReservation/selectRate/selectRate.ts @@ -1,13 +1,28 @@ -import { Product } from "@/server/routers/hotels/output" +import { Product, RoomConfiguration } from "@/server/routers/hotels/output" + +interface Child { + bed: string + age: number +} + +interface Room { + adults: number + roomtypecode: string + ratecode: string + child: Child[] +} export interface SelectRateSearchParams { - fromDate: string - toDate: string hotel: string + fromdate: string + todate: string + room: Room[] + [key: string]: string | string[] | Room[] } export interface Rate { - roomType: string + roomType: RoomConfiguration["roomType"] + roomTypeCode: RoomConfiguration["roomTypeCode"] priceName: string public: Product["productType"]["public"] member: Product["productType"]["member"]