From 6c88d3431a78b3e322e974db26448e25b11784d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20Landstr=C3=B6m?= Date: Tue, 17 Sep 2024 17:56:19 +0200 Subject: [PATCH] chore(SW-302): add dynamic restaurant title --- .../HotelPage/TabNavigation/index.tsx | 41 ++++++++++++----- components/ContentType/HotelPage/index.tsx | 16 +++++-- constants/routes/hotelPageParams.js | 32 ++++++++++++- types/components/hotelPage/tabNavigation.ts | 7 ++- utils/facilityCards.ts | 46 +++++++++++++++---- 5 files changed, 115 insertions(+), 27 deletions(-) diff --git a/components/ContentType/HotelPage/TabNavigation/index.tsx b/components/ContentType/HotelPage/TabNavigation/index.tsx index e594d757c..220139770 100644 --- a/components/ContentType/HotelPage/TabNavigation/index.tsx +++ b/components/ContentType/HotelPage/TabNavigation/index.tsx @@ -6,21 +6,40 @@ import useHash from "@/hooks/useHash" import styles from "./tabNavigation.module.css" -import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation" +import { + HotelHashValues, + type TabNavigationProps, +} from "@/types/components/hotelPage/tabNavigation" -export default function TabNavigation() { +export default function TabNavigation({ + restaurantRefData, +}: TabNavigationProps) { const hash = useHash() const intl = useIntl() - const hotelTabLinks: { href: HotelHashValues; text: string }[] = [ - // TODO these titles will need to reflect the facility card titles, which will vary between hotels - { href: HotelHashValues.overview, text: "Overview" }, - { href: HotelHashValues.rooms, text: "Rooms" }, - { href: HotelHashValues.restaurant, text: "Restaurant & Bar" }, - { href: HotelHashValues.meetings, text: "Meetings & Conferences" }, - { href: HotelHashValues.wellness, text: "Wellness & Exercise" }, - { href: HotelHashValues.activities, text: "Activities" }, - { href: HotelHashValues.faq, text: "FAQ" }, + const hotelTabLinks: { href: HotelHashValues | string; text: string }[] = [ + { + href: HotelHashValues.overview, + text: intl.formatMessage({ id: "Overview" }), + }, + { href: HotelHashValues.rooms, text: intl.formatMessage({ id: "Rooms" }) }, + { + href: "#" + restaurantRefData.href.en, + text: intl.formatMessage({ id: restaurantRefData.title }), + }, + { + href: HotelHashValues.meetings, + text: intl.formatMessage({ id: "Meetings & Conferences" }), + }, + { + href: HotelHashValues.wellness, + text: intl.formatMessage({ id: "Wellness & Exercise" }), + }, + { + href: HotelHashValues.activities, + text: intl.formatMessage({ id: "Activities" }), + }, + { href: HotelHashValues.faq, text: intl.formatMessage({ id: "FAQ" }) }, ] return ( diff --git a/components/ContentType/HotelPage/index.tsx b/components/ContentType/HotelPage/index.tsx index 1fcbb4a10..d6130acbc 100644 --- a/components/ContentType/HotelPage/index.tsx +++ b/components/ContentType/HotelPage/index.tsx @@ -7,7 +7,12 @@ import SidePeek from "@/components/TempDesignSystem/SidePeek" import { getIntl } from "@/i18n" import { getLang } from "@/i18n/serverContext" -import { setActivityCard, setFacilityCards } from "@/utils/facilityCards" +import { + getRestaurantDynamicTitles, + setActivityCard, + setFacilityCards, +} from "@/utils/facilityCards" + import DynamicMap from "./Map/DynamicMap" import MapCard from "./Map/MapCard" import MobileMapToggle from "./Map/MobileMapToggle" @@ -47,7 +52,10 @@ export default async function HotelPage() { facilityCards, } = hotelData - const facilities = await setFacilityCards(facilityCards) + const facilities = await setFacilityCards( + facilityCards, + hotelDetailedFacilities + ) activitiesCard && facilities.push(setActivityCard(activitiesCard)) const topThreePois = pointsOfInterest.slice(0, 3) @@ -61,7 +69,9 @@ export default async function HotelPage() {
- +
) { +export async function setFacilityCards( + facilities: Array, + amenities: HotelData["data"]["attributes"]["detailedFacilities"] +) { const lang = getLang() const intl = await getIntl() @@ -112,13 +119,14 @@ export async function setFacilityCards(facilities: Array) { break case FacilityEnum.restaurant: + const { href, title } = getRestaurantDynamicTitles(amenities) card.theme = "primaryDark" - card.id = "restaurant-and-bar" + card.id = href[lang] card.heading = intl.formatMessage({ id: "Enjoy relaxed restaurant experiences", }) card.secondaryButton = { - href: `?s=${restaurantAndBar[lang]}`, + href: `?s=${href[lang]}`, title: intl.formatMessage({ id: "Read more & book a table" }), isExternal: false, } @@ -130,10 +138,28 @@ export async function setFacilityCards(facilities: Array) { return cards } -/* lista över potentiella - Restaurant & Bar - Restaurants & bars - Restaurant - Bar - Breakfast restaurant (fallback om det inte finns restaurang eller bar) -*/ +export function getRestaurantDynamicTitles( + amenities: HotelData["data"]["attributes"]["detailedFacilities"] +) { + const hasBar = amenities.some( + (facility) => facility.id == 1606 || facility.id == 1014 // bar & rooftop bar id + ) + const hasRestaurant = amenities.some((facility) => facility.id == 1383) // restaurant id + + let href, title: string + if (hasBar && hasRestaurant) { + href = restaurantAndBar + title = "Restaurant & Bar" + } else if (hasBar) { + href = bar + title = "Bar" + } else if (hasRestaurant) { + href = restaurant + title = "Restaurant" + } else { + href = breakfastRestaurant + title = "Breakfast restaurant" + } + + return { href, title } +}