feat(SW-977): Scenario 2 & 4
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
export { default } from "../page"
|
||||||
@@ -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<ContentTypeParams>) {
|
||||||
|
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 <BookingWidget searchParams={params} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return <BookingWidget />
|
||||||
|
}
|
||||||
@@ -124,10 +124,12 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
|
|||||||
typeof window !== "undefined"
|
typeof window !== "undefined"
|
||||||
? sessionStorage.getItem(sessionStorageKey)
|
? sessionStorage.getItem(sessionStorageKey)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const searchHistory =
|
const searchHistory =
|
||||||
typeof window !== "undefined"
|
typeof window !== "undefined"
|
||||||
? localStorage.getItem(localStorageKey)
|
? localStorage.getItem(localStorageKey)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
if (searchData || searchHistory) {
|
if (searchData || searchHistory) {
|
||||||
dispatch({
|
dispatch({
|
||||||
payload: {
|
payload: {
|
||||||
@@ -160,13 +162,18 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
|
|||||||
}
|
}
|
||||||
}, [stayType, stayValue, unregister, setValue])
|
}, [stayType, stayValue, unregister, setValue])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
sessionStorage.setItem(sessionStorageKey, locationString)
|
||||||
|
}, [locationString])
|
||||||
|
|
||||||
function getLocationLabel(): string {
|
function getLocationLabel(): string {
|
||||||
if (state.searchData?.type === "hotels") {
|
|
||||||
return state.searchData?.relationships?.city?.name || ""
|
|
||||||
}
|
|
||||||
if (location?.type === "hotels") {
|
if (location?.type === "hotels") {
|
||||||
return location?.relationships?.city?.name || ""
|
return location?.relationships?.city?.name || ""
|
||||||
}
|
}
|
||||||
|
if (state.searchData?.type === "hotels") {
|
||||||
|
return state.searchData?.relationships?.city?.name || ""
|
||||||
|
}
|
||||||
|
|
||||||
return intl.formatMessage({ id: "Where to" })
|
return intl.formatMessage({ id: "Where to" })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user