diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_city_page/[uid]/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_city_page/[uid]/page.tsx index 179ad13e9..60398aebe 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_city_page/[uid]/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_city_page/[uid]/page.tsx @@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params" export { generateMetadata } from "@/utils/metadata/generateMetadata" export default async function DestinationCityPagePage( - props: PageArgs + props: PageArgs ) { const searchParams = await props.searchParams return (
}> - +
) diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_country_page/[uid]/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_country_page/[uid]/page.tsx index 3b0980346..f523389bf 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_country_page/[uid]/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/(contentTypes)/destination_country_page/[uid]/page.tsx @@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params" export { generateMetadata } from "@/utils/metadata/generateMetadata" export default async function DestinationCountryPagePage( - props: PageArgs + props: PageArgs ) { const searchParams = await props.searchParams return (
}> - +
) diff --git a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx index b7d33561d..c2d1739c6 100644 --- a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx +++ b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx @@ -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) diff --git a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCountryPage/index.tsx b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCountryPage/index.tsx index 761794be1..08878124d 100644 --- a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCountryPage/index.tsx +++ b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCountryPage/index.tsx @@ -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), diff --git a/apps/scandic-web/components/ContentType/DestinationPage/utils.ts b/apps/scandic-web/components/ContentType/DestinationPage/utils.ts index a6b348385..8bb867384 100644 --- a/apps/scandic-web/components/ContentType/DestinationPage/utils.ts +++ b/apps/scandic-web/components/ContentType/DestinationPage/utils.ts @@ -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) +}