feat(SW-302): switch out mock data for facility cards
This commit is contained in:
139
utils/facilityCards.ts
Normal file
139
utils/facilityCards.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
meetingsAndConferences,
|
||||
restaurantAndBar,
|
||||
wellnessAndExercise,
|
||||
} from "@/constants/routes/hotelPageParams"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import {
|
||||
type Facilities,
|
||||
type Facility as f,
|
||||
facilityEnum,
|
||||
} from "@/types/components/hotelPage/facilities"
|
||||
import type { ImageVaultAsset } from "@/types/components/imageVault"
|
||||
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
||||
import type { Facility } from "@/server/routers/hotels/output"
|
||||
|
||||
type ActivityCard = {
|
||||
background_image?: ImageVaultAsset
|
||||
scripted_title?: string
|
||||
heading: string
|
||||
body_text: string
|
||||
cta_text: string
|
||||
contentPage: Array<{ href: string }>
|
||||
}
|
||||
|
||||
export function setActivityCard(activitiesCard: ActivityCard): f {
|
||||
const hasImage = activitiesCard.background_image
|
||||
return [
|
||||
{
|
||||
id: "activities",
|
||||
theme: hasImage ? "image" : "primaryDark",
|
||||
scriptedTopTitle: activitiesCard.scripted_title,
|
||||
heading: activitiesCard.heading,
|
||||
bodyText: activitiesCard.body_text,
|
||||
backgroundImage: hasImage ? activitiesCard.background_image : undefined,
|
||||
primaryButton: hasImage
|
||||
? {
|
||||
href: activitiesCard.contentPage[0].href,
|
||||
title: activitiesCard.cta_text,
|
||||
isExternal: false,
|
||||
}
|
||||
: undefined,
|
||||
secondaryButton: hasImage
|
||||
? undefined
|
||||
: {
|
||||
href: activitiesCard.contentPage[0].href,
|
||||
title: activitiesCard.cta_text,
|
||||
isExternal: false,
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export async function setFacilityCards(facilities: Array<Facility>) {
|
||||
const lang = getLang()
|
||||
const intl = await getIntl()
|
||||
|
||||
let cards: Facilities = [],
|
||||
card: CardProps,
|
||||
grid: Array<CardProps>
|
||||
|
||||
facilities.map((facility) => {
|
||||
card = {}
|
||||
grid = []
|
||||
|
||||
card.scriptedTopTitle = facility.headingText
|
||||
|
||||
facility.heroImages.map((image) => {
|
||||
card = {}
|
||||
;(card.backgroundImage = {
|
||||
url: image.imageSizes.large,
|
||||
title: image.metaData.title,
|
||||
meta: {
|
||||
alt: image.metaData.altText,
|
||||
caption: image.metaData.altText_En,
|
||||
},
|
||||
}),
|
||||
(card.theme = "image")
|
||||
grid.push(card)
|
||||
})
|
||||
card = {}
|
||||
|
||||
switch (facility.id) {
|
||||
case facilityEnum.wellness:
|
||||
card.theme = "one"
|
||||
card.id = "wellness-and-exercise"
|
||||
;(card.heading = intl.formatMessage({ id: "Sauna and gym" })),
|
||||
(card.secondaryButton = {
|
||||
href: `?s=${wellnessAndExercise[lang]}`,
|
||||
title: intl.formatMessage({
|
||||
id: "Read more about wellness & exercise",
|
||||
}),
|
||||
isExternal: false,
|
||||
})
|
||||
grid.unshift(card)
|
||||
break
|
||||
|
||||
case facilityEnum.conference:
|
||||
card.theme = "primaryDim"
|
||||
card.id = "meetings-and-conferences"
|
||||
;(card.heading = intl.formatMessage({
|
||||
id: "Events that make an impression",
|
||||
})),
|
||||
(card.secondaryButton = {
|
||||
href: `?s=${meetingsAndConferences[lang]}`,
|
||||
title: intl.formatMessage({ id: "About meetings & conferences" }),
|
||||
isExternal: false,
|
||||
})
|
||||
grid.push(card)
|
||||
break
|
||||
|
||||
case facilityEnum.restaurant:
|
||||
card.theme = "primaryDark"
|
||||
card.id = "restaurant-and-bar"
|
||||
card.heading = intl.formatMessage({
|
||||
id: "Enjoy relaxed restaurant experiences",
|
||||
})
|
||||
card.secondaryButton = {
|
||||
href: `?s=${restaurantAndBar[lang]}`,
|
||||
title: intl.formatMessage({ id: "Read more & book a table" }),
|
||||
isExternal: false,
|
||||
}
|
||||
grid.unshift(card)
|
||||
break
|
||||
}
|
||||
cards.push(grid)
|
||||
})
|
||||
return cards
|
||||
}
|
||||
|
||||
/* lista över potentiella
|
||||
Restaurant & Bar
|
||||
Restaurants & bars
|
||||
Restaurant
|
||||
Bar
|
||||
Breakfast restaurant (fallback om det inte finns restaurang eller bar)
|
||||
*/
|
||||
@@ -1,10 +1,8 @@
|
||||
import type {
|
||||
Facility,
|
||||
FacilityCard,
|
||||
} from "@/types/components/hotelPage/facilities"
|
||||
import type { Facility } from "@/types/components/hotelPage/facilities"
|
||||
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
||||
|
||||
export function sortCards(grid: Facility) {
|
||||
const sortedCards = grid.slice(0).sort((a: FacilityCard, b: FacilityCard) => {
|
||||
const sortedCards = grid.slice(0).sort((a: CardProps, b: CardProps) => {
|
||||
if (!a.backgroundImage && b.backgroundImage) {
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user