60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
|
|
|
import { removeMultipleSlashes } from "@/utils/url"
|
|
|
|
import { tempImageVaultAssetSchema } from "../imageVault"
|
|
|
|
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
|
|
|
export const activitiesCard = z.object({
|
|
typename: z
|
|
.literal(HotelPageEnum.ContentStack.blocks.ActivitiesCard)
|
|
.optional()
|
|
.default(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
|
upcoming_activities_card: z
|
|
.object({
|
|
background_image: tempImageVaultAssetSchema,
|
|
body_text: z.string(),
|
|
cta_text: z.string(),
|
|
heading: z.string(),
|
|
open_in_new_tab: z.boolean(),
|
|
scripted_title: z.string().optional(),
|
|
hotel_page_activities_content_pageConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.discriminatedUnion("__typename", [
|
|
pageLinks.contentPageSchema,
|
|
]),
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
let contentPage = { href: "" }
|
|
if (data.hotel_page_activities_content_pageConnection.edges.length) {
|
|
const page =
|
|
data.hotel_page_activities_content_pageConnection.edges[0].node
|
|
if (page.web.original_url) {
|
|
contentPage = {
|
|
href: page.web.original_url,
|
|
}
|
|
} else {
|
|
contentPage = {
|
|
href: removeMultipleSlashes(`/${page.system.locale}/${page.url}`),
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
background_image: data.background_image,
|
|
body_text: data.body_text,
|
|
contentPage,
|
|
cta_text: data.cta_text,
|
|
heading: data.heading,
|
|
open_in_new_tab: !!data.open_in_new_tab,
|
|
scripted_title: data.scripted_title,
|
|
}
|
|
}),
|
|
})
|