From c635a8b072e8743c63c79fd0ab40d45a81f024f5 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Wed, 11 Dec 2024 14:53:51 +0100 Subject: [PATCH] feat(SW-977): Scenario 2 & 4 --- .../[contentType]/[uid]/[...paths]/page.tsx | 1 + .../[contentType]/[uid]/page.tsx | 31 +++++++++++++++++++ .../FormContent/Search/index.tsx | 13 ++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/[...paths]/page.tsx create mode 100644 app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/page.tsx diff --git a/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/[...paths]/page.tsx b/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/[...paths]/page.tsx new file mode 100644 index 000000000..03a82e5f5 --- /dev/null +++ b/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/[...paths]/page.tsx @@ -0,0 +1 @@ +export { default } from "../page" diff --git a/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/page.tsx b/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/page.tsx new file mode 100644 index 000000000..043da7c54 --- /dev/null +++ b/app/[lang]/(live)/@bookingwidget/[contentType]/[uid]/page.tsx @@ -0,0 +1,31 @@ +import { env } from "@/env/server" +import { getHotelData, getHotelPage } from "@/lib/trpc/memoizedRequests" + +import BookingWidget, { preload } from "@/components/BookingWidget" +import { getLang } from "@/i18n/serverContext" + +import { ContentTypeParams, PageArgs } from "@/types/params" + +export default async function BookingWidgetPage({ + params, +}: PageArgs) { + if (!env.ENABLE_BOOKING_WIDGET_HOTELRESERVATION_PATH) return null + + preload() + + if (params.contentType === "hotel-page") { + const hotelPageData = await getHotelPage() + + const hotelData = await getHotelData({ + hotelId: hotelPageData?.hotel_page_id || "", + language: getLang(), + }) + const params = new URLSearchParams() + params.set("hotel", hotelData?.data?.id || "") + params.set("city", hotelData?.data?.attributes?.cityName || "") + + return + } + + return +} diff --git a/components/Forms/BookingWidget/FormContent/Search/index.tsx b/components/Forms/BookingWidget/FormContent/Search/index.tsx index 607fb709b..92b2edfc4 100644 --- a/components/Forms/BookingWidget/FormContent/Search/index.tsx +++ b/components/Forms/BookingWidget/FormContent/Search/index.tsx @@ -124,10 +124,12 @@ export default function Search({ locations, handlePressEnter }: SearchProps) { typeof window !== "undefined" ? sessionStorage.getItem(sessionStorageKey) : undefined + const searchHistory = typeof window !== "undefined" ? localStorage.getItem(localStorageKey) : null + if (searchData || searchHistory) { dispatch({ payload: { @@ -160,13 +162,18 @@ export default function Search({ locations, handlePressEnter }: SearchProps) { } }, [stayType, stayValue, unregister, setValue]) + useEffect(() => { + sessionStorage.setItem(sessionStorageKey, locationString) + }, [locationString]) + function getLocationLabel(): string { - if (state.searchData?.type === "hotels") { - return state.searchData?.relationships?.city?.name || "" - } if (location?.type === "hotels") { return location?.relationships?.city?.name || "" } + if (state.searchData?.type === "hotels") { + return state.searchData?.relationships?.city?.name || "" + } + return intl.formatMessage({ id: "Where to" }) }