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:
@@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params"
|
|||||||
export { generateMetadata } from "@/utils/metadata/generateMetadata"
|
export { generateMetadata } from "@/utils/metadata/generateMetadata"
|
||||||
|
|
||||||
export default async function DestinationCityPagePage(
|
export default async function DestinationCityPagePage(
|
||||||
props: PageArgs<object, { view?: "map" }>
|
props: PageArgs<object, { view?: "map"; filterFromUrl?: string }>
|
||||||
) {
|
) {
|
||||||
const searchParams = await props.searchParams
|
const searchParams = await props.searchParams
|
||||||
return (
|
return (
|
||||||
<div className={styles.page}>
|
<div className={styles.page}>
|
||||||
<Suspense fallback={<DestinationCityPageSkeleton />}>
|
<Suspense fallback={<DestinationCityPageSkeleton />}>
|
||||||
<DestinationCityPage isMapView={searchParams.view === "map"} />
|
<DestinationCityPage
|
||||||
|
isMapView={searchParams.view === "map"}
|
||||||
|
filterFromUrl={searchParams.filterFromUrl}
|
||||||
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,13 +10,16 @@ import type { PageArgs } from "@/types/params"
|
|||||||
export { generateMetadata } from "@/utils/metadata/generateMetadata"
|
export { generateMetadata } from "@/utils/metadata/generateMetadata"
|
||||||
|
|
||||||
export default async function DestinationCountryPagePage(
|
export default async function DestinationCountryPagePage(
|
||||||
props: PageArgs<object, { view?: "map" }>
|
props: PageArgs<object, { view?: "map"; filterFromUrl?: string }>
|
||||||
) {
|
) {
|
||||||
const searchParams = await props.searchParams
|
const searchParams = await props.searchParams
|
||||||
return (
|
return (
|
||||||
<div className={styles.page}>
|
<div className={styles.page}>
|
||||||
<Suspense fallback={<DestinationCountryPageSkeleton />}>
|
<Suspense fallback={<DestinationCountryPageSkeleton />}>
|
||||||
<DestinationCountryPage isMapView={searchParams.view === "map"} />
|
<DestinationCountryPage
|
||||||
|
filterFromUrl={searchParams.filterFromUrl}
|
||||||
|
isMapView={searchParams.view === "map"}
|
||||||
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { notFound } from "next/navigation"
|
import { notFound, redirect } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +29,7 @@ import DestinationPageSidePeek from "../Sidepeek"
|
|||||||
import StaticMap from "../StaticMap"
|
import StaticMap from "../StaticMap"
|
||||||
import TopImages from "../TopImages"
|
import TopImages from "../TopImages"
|
||||||
import DestinationTracking from "../Tracking"
|
import DestinationTracking from "../Tracking"
|
||||||
|
import { isValidSeoFilter } from "../utils"
|
||||||
import CityMap from "./CityMap"
|
import CityMap from "./CityMap"
|
||||||
import DestinationCityPageSkeleton from "./DestinationCityPageSkeleton"
|
import DestinationCityPageSkeleton from "./DestinationCityPageSkeleton"
|
||||||
|
|
||||||
@@ -36,10 +37,12 @@ import styles from "./destinationCityPage.module.css"
|
|||||||
|
|
||||||
interface DestinationCityPageProps {
|
interface DestinationCityPageProps {
|
||||||
isMapView: boolean
|
isMapView: boolean
|
||||||
|
filterFromUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function DestinationCityPage({
|
export default async function DestinationCityPage({
|
||||||
isMapView,
|
isMapView,
|
||||||
|
filterFromUrl,
|
||||||
}: DestinationCityPageProps) {
|
}: DestinationCityPageProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const lang = await getLang()
|
const lang = await getLang()
|
||||||
@@ -63,6 +66,11 @@ export default async function DestinationCityPage({
|
|||||||
seo_filters,
|
seo_filters,
|
||||||
} = destinationCityPage
|
} = destinationCityPage
|
||||||
|
|
||||||
|
if (!isValidSeoFilter(seo_filters, filterFromUrl)) {
|
||||||
|
const updatedPathname = pathname.replace(`/${filterFromUrl}`, "")
|
||||||
|
return redirect(`${updatedPathname}${isMapView ? "?view=map" : ""}`)
|
||||||
|
}
|
||||||
|
|
||||||
const allHotels = await getHotelsByCityIdentifier(cityIdentifier)
|
const allHotels = await getHotelsByCityIdentifier(cityIdentifier)
|
||||||
const hotelFilters = getFiltersFromHotels(allHotels, lang)
|
const hotelFilters = getFiltersFromHotels(allHotels, lang)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { notFound } from "next/navigation"
|
import { notFound, redirect } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -30,6 +30,7 @@ import DestinationPageSidePeek from "../Sidepeek"
|
|||||||
import StaticMap from "../StaticMap"
|
import StaticMap from "../StaticMap"
|
||||||
import TopImages from "../TopImages"
|
import TopImages from "../TopImages"
|
||||||
import DestinationTracking from "../Tracking"
|
import DestinationTracking from "../Tracking"
|
||||||
|
import { isValidSeoFilter } from "../utils"
|
||||||
import CountryMap from "./CountryMap"
|
import CountryMap from "./CountryMap"
|
||||||
import DestinationCountryPageSkeleton from "./DestinationCountryPageSkeleton"
|
import DestinationCountryPageSkeleton from "./DestinationCountryPageSkeleton"
|
||||||
|
|
||||||
@@ -37,10 +38,12 @@ import styles from "./destinationCountryPage.module.css"
|
|||||||
|
|
||||||
interface DestinationCountryPageProps {
|
interface DestinationCountryPageProps {
|
||||||
isMapView: boolean
|
isMapView: boolean
|
||||||
|
filterFromUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function DestinationCountryPage({
|
export default async function DestinationCountryPage({
|
||||||
isMapView,
|
isMapView,
|
||||||
|
filterFromUrl,
|
||||||
}: DestinationCountryPageProps) {
|
}: DestinationCountryPageProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const lang = await getLang()
|
const lang = await getLang()
|
||||||
@@ -64,6 +67,11 @@ export default async function DestinationCountryPage({
|
|||||||
seo_filters,
|
seo_filters,
|
||||||
} = destinationCountryPage
|
} = destinationCountryPage
|
||||||
|
|
||||||
|
if (!isValidSeoFilter(seo_filters, filterFromUrl)) {
|
||||||
|
const updatedPathname = pathname.replace(`/${filterFromUrl}`, "")
|
||||||
|
return redirect(`${updatedPathname}${isMapView ? "?view=map" : ""}`)
|
||||||
|
}
|
||||||
|
|
||||||
const [allHotels, allCities] = await Promise.all([
|
const [allHotels, allCities] = await Promise.all([
|
||||||
getHotelsByCountry(destination_settings.country),
|
getHotelsByCountry(destination_settings.country),
|
||||||
getDestinationCityPagesByCountry(destination_settings.country),
|
getDestinationCityPagesByCountry(destination_settings.country),
|
||||||
|
|||||||
@@ -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"
|
import type { IntlShape } from "react-intl"
|
||||||
|
|
||||||
export function getHeadingText(
|
export function getHeadingText(
|
||||||
@@ -41,3 +44,14 @@ export function getPreambleText(
|
|||||||
|
|
||||||
return defaultPreamble
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user