Merged in feat/BOOK-434-users-should-redirect-to- (pull request #3087)

* feat(BOOK-434): Redirect user to city/country page if wrong filter url
* feat(BOOK-434): Handled map view

Approved-by: Erik Tiekstra
This commit is contained in:
Hrishikesh Vaipurkar
2025-11-07 10:30:00 +00:00
parent 61af689853
commit 28ae796b8c
5 changed files with 43 additions and 7 deletions

View File

@@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params"
export { generateMetadata } from "@/utils/metadata/generateMetadata"
export default async function DestinationCityPagePage(
props: PageArgs<object, { view?: "map" }>
props: PageArgs<object, { view?: "map"; filterFromUrl?: string }>
) {
const searchParams = await props.searchParams
return (
<div className={styles.page}>
<Suspense fallback={<DestinationCityPageSkeleton />}>
<DestinationCityPage isMapView={searchParams.view === "map"} />
<DestinationCityPage
isMapView={searchParams.view === "map"}
filterFromUrl={searchParams.filterFromUrl}
/>
</Suspense>
</div>
)

View File

@@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params"
export { generateMetadata } from "@/utils/metadata/generateMetadata"
export default async function DestinationCountryPagePage(
props: PageArgs<object, { view?: "map" }>
props: PageArgs<object, { view?: "map"; filterFromUrl?: string }>
) {
const searchParams = await props.searchParams
return (
<div className={styles.page}>
<Suspense fallback={<DestinationCountryPageSkeleton />}>
<DestinationCountryPage isMapView={searchParams.view === "map"} />
<DestinationCountryPage
filterFromUrl={searchParams.filterFromUrl}
isMapView={searchParams.view === "map"}
/>
</Suspense>
</div>
)

View File

@@ -1,4 +1,4 @@
import { notFound } from "next/navigation"
import { notFound, redirect } from "next/navigation"
import { Suspense } from "react"
import {
@@ -29,6 +29,7 @@ import DestinationPageSidePeek from "../Sidepeek"
import StaticMap from "../StaticMap"
import TopImages from "../TopImages"
import DestinationTracking from "../Tracking"
import { isValidSeoFilter } from "../utils"
import CityMap from "./CityMap"
import DestinationCityPageSkeleton from "./DestinationCityPageSkeleton"
@@ -36,10 +37,12 @@ import styles from "./destinationCityPage.module.css"
interface DestinationCityPageProps {
isMapView: boolean
filterFromUrl?: string
}
export default async function DestinationCityPage({
isMapView,
filterFromUrl,
}: DestinationCityPageProps) {
const intl = await getIntl()
const lang = await getLang()
@@ -63,6 +66,11 @@ export default async function DestinationCityPage({
seo_filters,
} = destinationCityPage
if (!isValidSeoFilter(seo_filters, filterFromUrl)) {
const updatedPathname = pathname.replace(`/${filterFromUrl}`, "")
return redirect(`${updatedPathname}${isMapView ? "?view=map" : ""}`)
}
const allHotels = await getHotelsByCityIdentifier(cityIdentifier)
const hotelFilters = getFiltersFromHotels(allHotels, lang)

View File

@@ -1,4 +1,4 @@
import { notFound } from "next/navigation"
import { notFound, redirect } from "next/navigation"
import { Suspense } from "react"
import {
@@ -30,6 +30,7 @@ import DestinationPageSidePeek from "../Sidepeek"
import StaticMap from "../StaticMap"
import TopImages from "../TopImages"
import DestinationTracking from "../Tracking"
import { isValidSeoFilter } from "../utils"
import CountryMap from "./CountryMap"
import DestinationCountryPageSkeleton from "./DestinationCountryPageSkeleton"
@@ -37,10 +38,12 @@ import styles from "./destinationCountryPage.module.css"
interface DestinationCountryPageProps {
isMapView: boolean
filterFromUrl?: string
}
export default async function DestinationCountryPage({
isMapView,
filterFromUrl,
}: DestinationCountryPageProps) {
const intl = await getIntl()
const lang = await getLang()
@@ -64,6 +67,11 @@ export default async function DestinationCountryPage({
seo_filters,
} = destinationCountryPage
if (!isValidSeoFilter(seo_filters, filterFromUrl)) {
const updatedPathname = pathname.replace(`/${filterFromUrl}`, "")
return redirect(`${updatedPathname}${isMapView ? "?view=map" : ""}`)
}
const [allHotels, allCities] = await Promise.all([
getHotelsByCountry(destination_settings.country),
getDestinationCityPagesByCountry(destination_settings.country),

View File

@@ -1,4 +1,7 @@
import type { DestinationFilter } from "@scandic-hotels/trpc/types/destinationsData"
import type {
DestinationFilter,
DestinationFilters,
} from "@scandic-hotels/trpc/types/destinationsData"
import type { IntlShape } from "react-intl"
export function getHeadingText(
@@ -41,3 +44,14 @@ export function getPreambleText(
return defaultPreamble
}
export function isValidSeoFilter(
seoFilters: DestinationFilters,
filterFromUrl?: string
) {
const flattenedSeoFilters = Object.values(seoFilters).flat()
if (!filterFromUrl || !flattenedSeoFilters.length) {
return true
}
return flattenedSeoFilters.some((f) => f.filter.slug === filterFromUrl)
}