Files
web/apps/scandic-web/components/Blocks/HotelListing/HotelListingItem/utils.ts

72 lines
2.0 KiB
TypeScript

import type { IntlShape } from "react-intl"
import type { AdditionalData, Hotel } from "@/types/hotel"
import type { HotelListing } from "@/types/trpc/routers/contentstack/blocks"
export function getTypeSpecificInformation(
intl: IntlShape,
contentType: HotelListing["contentType"],
hotelContent: Hotel["hotelContent"],
additionalData: AdditionalData,
url: string | null
) {
const { images, texts } = hotelContent
const { descriptions, meetingDescription } = texts
const { conferencesAndMeetings, restaurantsOverviewPage, restaurantImages } =
additionalData
const data = {
description: descriptions?.short,
image: {
src: images.imageSizes.small,
alt: images.metaData.altText,
},
cta: {
text: intl.formatMessage({
defaultMessage: "See hotel details",
}),
url,
openInNewTab: false,
},
}
switch (contentType) {
case "meeting":
const meetingImage = conferencesAndMeetings?.heroImages[0]
const meetingUrl = additionalData.meetingRooms.meetingOnlineLink
if (meetingDescription?.short) {
data.description = meetingDescription.short
}
if (meetingImage) {
data.image = {
src: meetingImage.imageSizes.small,
alt: meetingImage.metaData.altText,
}
}
if (meetingUrl) {
data.cta = {
text: intl.formatMessage({
defaultMessage: "Book a meeting",
}),
url: meetingUrl,
openInNewTab: true,
}
}
return data
case "restaurant":
const restaurantImage = restaurantImages?.heroImages[0]
if (restaurantsOverviewPage.restaurantsContentDescriptionShort) {
data.description =
restaurantsOverviewPage.restaurantsContentDescriptionShort
}
if (restaurantImage) {
data.image = {
src: restaurantImage.imageSizes.small,
alt: restaurantImage.metaData.altText,
}
}
return data
case "hotel":
default:
return data
}
}