fix: enable localization of sidepeek params

This commit is contained in:
Arvid Norlin
2024-08-12 10:52:29 +02:00
parent 47c77b62d6
commit 04eb3c6d94
7 changed files with 49 additions and 9 deletions

View File

@@ -1,3 +1,6 @@
import { Lang } from "@/constants/languages"
import { amenities } from "@/constants/routes/hotelPageParams"
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data" import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
import { ChevronRightIcon } from "@/components/Icons" import { ChevronRightIcon } from "@/components/Icons"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
@@ -12,11 +15,14 @@ import { HotelData } from "@/types/hotel"
export default async function AmenitiesList({ export default async function AmenitiesList({
detailedFacilities, detailedFacilities,
// TODO: remove prop drilling once getLang() is merged
lang,
}: { }: {
detailedFacilities: HotelData["data"]["attributes"]["detailedFacilities"] detailedFacilities: HotelData["data"]["attributes"]["detailedFacilities"]
lang: Lang
}) { }) {
const { formatMessage } = await getIntl() const { formatMessage } = await getIntl()
const sidePeekLink = generateSidePeekLink("amenities") const sidePeekLink = generateSidePeekLink(amenities[lang])
const sortedAmenities = detailedFacilities const sortedAmenities = detailedFacilities
.sort((a, b) => b.sortOrder - a.sortOrder) .sort((a, b) => b.sortOrder - a.sortOrder)
.slice(0, 5) .slice(0, 5)

View File

@@ -1,3 +1,4 @@
import { about, amenities } from "@/constants/routes/hotelPageParams"
import { serverClient } from "@/lib/trpc/server" import { serverClient } from "@/lib/trpc/server"
import { getLang } from "@/i18n/serverContext" import { getLang } from "@/i18n/serverContext"
@@ -34,6 +35,8 @@ export default async function HotelPage() {
<main className={styles.mainSection}> <main className={styles.mainSection}>
<div className={styles.introContainer}> <div className={styles.introContainer}>
<IntroSection <IntroSection
// TODO: remove prop drilling once getLang() is merged
lang={lang}
hotelName={attributes.name} hotelName={attributes.name}
hotelDescription={attributes.hotelContent.texts.descriptions.short} hotelDescription={attributes.hotelContent.texts.descriptions.short}
location={attributes.location} location={attributes.location}
@@ -55,7 +58,10 @@ export default async function HotelPage() {
Some additional information about the hotel Some additional information about the hotel
</SidePeekContent> </SidePeekContent>
</SidePeekContainer> </SidePeekContainer>
<AmenitiesList detailedFacilities={attributes.detailedFacilities} /> <AmenitiesList
detailedFacilities={attributes.detailedFacilities}
lang={lang}
/>
</div> </div>
<Rooms rooms={roomCategories} /> <Rooms rooms={roomCategories} />
</main> </main>

View File

@@ -1,3 +1,5 @@
import { about } from "@/constants/routes/hotelPageParams"
import ArrowRight from "@/components/Icons/ArrowRight" import ArrowRight from "@/components/Icons/ArrowRight"
import TripAdvisorIcon from "@/components/Icons/TripAdvisor" import TripAdvisorIcon from "@/components/Icons/TripAdvisor"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
@@ -18,6 +20,8 @@ export default async function IntroSection({
location, location,
address, address,
tripAdvisor, tripAdvisor,
// TODO: remove prop drilling once getLang() is merged
lang,
}: IntroSectionProps) { }: IntroSectionProps) {
const intl = await getIntl() const intl = await getIntl()
const { formatMessage } = intl const { formatMessage } = intl
@@ -32,7 +36,7 @@ export default async function IntroSection({
{ id: "Tripadvisor reviews" }, { id: "Tripadvisor reviews" },
{ rating: tripAdvisor.rating, count: tripAdvisor.numberOfReviews } { rating: tripAdvisor.rating, count: tripAdvisor.numberOfReviews }
) )
const aboutTheHotelLink = generateSidePeekLink("about") const aboutTheHotelLink = generateSidePeekLink(about[lang])
return ( return (
<section className={styles.introSection}> <section className={styles.introSection}>

View File

@@ -1,3 +1,5 @@
import { Lang } from "@/constants/languages"
import { import {
HotelAddress, HotelAddress,
HotelData, HotelData,
@@ -11,4 +13,6 @@ export type IntroSectionProps = {
location: HotelLocation location: HotelLocation
address: HotelAddress address: HotelAddress
tripAdvisor: HotelTripAdvisor tripAdvisor: HotelTripAdvisor
// TODO: remove prop drilling once getLang() is merged
lang: Lang
} }

View File

@@ -15,15 +15,13 @@ export default function SidePeekContainer({
const [activeSidePeek, setActiveSidePeek] = const [activeSidePeek, setActiveSidePeek] =
useState<SidePeekContentKey | null>(() => { useState<SidePeekContentKey | null>(() => {
const sidePeekParam = searchParams.get( const sidePeekParam = searchParams.get(
"sidepeek" "open"
) as SidePeekContentKey | null ) as SidePeekContentKey | null
return sidePeekParam || null return sidePeekParam || null
}) })
useEffect(() => { useEffect(() => {
const sidePeekParam = searchParams.get( const sidePeekParam = searchParams.get("open") as SidePeekContentKey | null
"sidepeek"
) as SidePeekContentKey | null
if (sidePeekParam !== activeSidePeek) { if (sidePeekParam !== activeSidePeek) {
setActiveSidePeek(sidePeekParam) setActiveSidePeek(sidePeekParam)
} }
@@ -34,7 +32,7 @@ export default function SidePeekContainer({
setActiveSidePeek(null) setActiveSidePeek(null)
const nextSearchParams = new URLSearchParams(searchParams.toString()) const nextSearchParams = new URLSearchParams(searchParams.toString())
nextSearchParams.delete("sidepeek") nextSearchParams.delete("open")
router.push(`${pathname}?${nextSearchParams}`, { scroll: false }) router.push(`${pathname}?${nextSearchParams}`, { scroll: false })
} }

View File

@@ -1,5 +1,6 @@
import { SidePeekContentKey } from "./types" import { SidePeekContentKey } from "./types"
export const generateSidePeekLink = (key: SidePeekContentKey) => { export const generateSidePeekLink = (key: SidePeekContentKey) => {
return `?sidepeek=${key}` // what should the parameter be named to make sense in all use cases/languages? single caracter? like`s=`?
return `?open=${key}`
} }

View File

@@ -0,0 +1,21 @@
export const about = {
en: "about",
sv: "om-hotellet",
no: "om-hotellet",
fi: "hotellista",
da: "om-hotellet",
de: "uber-das-hotel",
}
export const amenities = {
en: "amenities",
sv: "bekvamligheter",
no: "fasiliteter",
da: "faciliteter",
fi: "palvelut",
de: "annehmlichkeiten",
}
const params = { about, amenities }
export default params