From d8bc677b4dc7c81a4b619a2f781eb448b9c773cb Mon Sep 17 00:00:00 2001 From: Bianca Widstam Date: Fri, 25 Oct 2024 06:48:29 +0000 Subject: [PATCH] feat/SW-627-query-available-hotels (pull request #751) Feat/SW-627 query available hotels * feat(SW-627): use correct search query to find available hotels * feat(SW-627): fix type name * feat(SW-627): update correct params * feat(SW-627): update correct params type * feat(SW-627): fix select hotel searchParams type Approved-by: Niclas Edenvin --- .../(standard)/select-hotel/page.tsx | 37 +++++++++++++++---- .../selectHotel/selectHotelSearchParams.ts | 17 +++++++++ .../hotelReservation/selectRate/selectRate.ts | 4 +- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 types/components/hotelReservation/selectHotel/selectHotelSearchParams.ts diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/page.tsx index 7dcec9130..1591e811b 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/page.tsx @@ -1,4 +1,7 @@ +import { notFound } from "next/navigation" + import { selectHotelMap } from "@/constants/routes/hotelReservation" +import { getLocations } from "@/lib/trpc/memoizedRequests" import { fetchAvailableHotels, @@ -6,6 +9,7 @@ import { } from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils" import HotelCardListing from "@/components/HotelReservation/HotelCardListing" import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter" +import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils" import { ChevronRightIcon } from "@/components/Icons" import StaticMap from "@/components/Maps/StaticMap" import Link from "@/components/TempDesignSystem/Link" @@ -14,21 +18,38 @@ import { setLang } from "@/i18n/serverContext" import styles from "./page.module.css" +import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams" import { LangParams, PageArgs } from "@/types/params" export default async function SelectHotelPage({ params, -}: PageArgs) { + searchParams, +}: PageArgs) { setLang(params.lang) + const locations = await getLocations() + + if (!locations || "error" in locations) { + return null + } + const city = locations.data.find( + (location) => + location.name.toLowerCase() === searchParams.city.toLowerCase() + ) + if (!city) return notFound() - const tempSearchTerm = "Stockholm" const intl = await getIntl() + const selectHotelParams = new URLSearchParams(searchParams) + const selectHotelParamsObject = + getHotelReservationQueryParams(selectHotelParams) + const adults = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms + const children = selectHotelParamsObject.room[0].child?.length // TODO: Handle multiple rooms const hotels = await fetchAvailableHotels({ - cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", - roomStayStartDate: "2024-11-02", - roomStayEndDate: "2024-11-03", - adults: 1, + cityId: city.id, + roomStayStartDate: searchParams.fromDate, + roomStayEndDate: searchParams.toDate, + adults, + children, }) const filterList = getFiltersFromHotels(hotels) @@ -38,12 +59,12 @@ export default async function SelectHotelPage({