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
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
import { selectHotelMap } from "@/constants/routes/hotelReservation"
|
import { selectHotelMap } from "@/constants/routes/hotelReservation"
|
||||||
|
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
fetchAvailableHotels,
|
fetchAvailableHotels,
|
||||||
@@ -6,6 +9,7 @@ import {
|
|||||||
} 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 { 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"
|
||||||
@@ -14,21 +18,38 @@ import { setLang } from "@/i18n/serverContext"
|
|||||||
|
|
||||||
import styles from "./page.module.css"
|
import styles from "./page.module.css"
|
||||||
|
|
||||||
|
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||||
import { LangParams, PageArgs } from "@/types/params"
|
import { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|
||||||
export default async function SelectHotelPage({
|
export default async function SelectHotelPage({
|
||||||
params,
|
params,
|
||||||
}: PageArgs<LangParams>) {
|
searchParams,
|
||||||
|
}: PageArgs<LangParams, SelectHotelSearchParams>) {
|
||||||
setLang(params.lang)
|
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 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({
|
const hotels = await fetchAvailableHotels({
|
||||||
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
cityId: city.id,
|
||||||
roomStayStartDate: "2024-11-02",
|
roomStayStartDate: searchParams.fromDate,
|
||||||
roomStayEndDate: "2024-11-03",
|
roomStayEndDate: searchParams.toDate,
|
||||||
adults: 1,
|
adults,
|
||||||
|
children,
|
||||||
})
|
})
|
||||||
|
|
||||||
const filterList = getFiltersFromHotels(hotels)
|
const filterList = getFiltersFromHotels(hotels)
|
||||||
@@ -38,12 +59,12 @@ export default async function SelectHotelPage({
|
|||||||
<section className={styles.section}>
|
<section className={styles.section}>
|
||||||
<Link href={selectHotelMap[params.lang]} keepSearchParams>
|
<Link href={selectHotelMap[params.lang]} keepSearchParams>
|
||||||
<StaticMap
|
<StaticMap
|
||||||
city={tempSearchTerm}
|
city={searchParams.city}
|
||||||
width={340}
|
width={340}
|
||||||
height={180}
|
height={180}
|
||||||
zoomLevel={11}
|
zoomLevel={11}
|
||||||
mapType="roadmap"
|
mapType="roadmap"
|
||||||
altText={`Map of ${tempSearchTerm} city center`}
|
altText={`Map of ${searchParams.city} city center`}
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
interface Child {
|
||||||
|
bed: string
|
||||||
|
age: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Room {
|
||||||
|
adults: number
|
||||||
|
child?: Child[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelectHotelSearchParams {
|
||||||
|
city: string
|
||||||
|
fromDate: string
|
||||||
|
toDate: string
|
||||||
|
room: Room[]
|
||||||
|
[key: string]: string | string[] | Room[]
|
||||||
|
}
|
||||||
@@ -14,8 +14,8 @@ interface Room {
|
|||||||
|
|
||||||
export interface SelectRateSearchParams {
|
export interface SelectRateSearchParams {
|
||||||
hotel: string
|
hotel: string
|
||||||
fromdate: string
|
fromDate: string
|
||||||
todate: string
|
toDate: string
|
||||||
room: Room[]
|
room: Room[]
|
||||||
[key: string]: string | string[] | Room[]
|
[key: string]: string | string[] | Room[]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user