feat(SW-1443): added carousel block on hotel overview page * feat(SW-1443): added carousel block on hotel overview page Approved-by: Fredrik Thorsson Approved-by: Matilda Landström Approved-by: Chuma Mcphoy (We Ahead)
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
|
|
|
import { removeMultipleSlashes } from "@/utils/url"
|
|
|
|
import {
|
|
carouselCardsRefsSchema,
|
|
carouselCardsSchema,
|
|
} from "../schemas/blocks/carouselCards"
|
|
import { systemSchema } from "../schemas/system"
|
|
|
|
import { DestinationOverviewPageEnum } from "@/types/enums/destinationOverviewPage"
|
|
|
|
const destinationOverviewPageCarouselCards = z
|
|
.object({
|
|
__typename: z.literal(
|
|
DestinationOverviewPageEnum.ContentStack.blocks.CarouselCards
|
|
),
|
|
})
|
|
.merge(carouselCardsSchema)
|
|
|
|
export const blocksSchema = z.discriminatedUnion("__typename", [
|
|
destinationOverviewPageCarouselCards,
|
|
])
|
|
|
|
export const destinationOverviewPageSchema = z.object({
|
|
destination_overview_page: z.object({
|
|
title: z.string(),
|
|
blocks: discriminatedUnionArray(blocksSchema.options),
|
|
system: systemSchema.merge(
|
|
z.object({
|
|
created_at: z.string(),
|
|
updated_at: z.string(),
|
|
})
|
|
),
|
|
}),
|
|
trackingProps: z.object({
|
|
url: z.string(),
|
|
}),
|
|
})
|
|
|
|
export const countryPageUrlSchema = z
|
|
.object({
|
|
all_destination_country_page: z.object({
|
|
items: z.array(
|
|
z
|
|
.object({
|
|
url: z.string(),
|
|
system: systemSchema,
|
|
})
|
|
.transform((data) => {
|
|
return {
|
|
url: removeMultipleSlashes(`/${data.system.locale}/${data.url}`),
|
|
}
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform(
|
|
({ all_destination_country_page }) => all_destination_country_page.items[0]
|
|
)
|
|
|
|
/** REFS */
|
|
const destinationOverviewPageCarouselCardsRef = z
|
|
.object({
|
|
__typename: z.literal(
|
|
DestinationOverviewPageEnum.ContentStack.blocks.CarouselCards
|
|
),
|
|
})
|
|
.merge(carouselCardsRefsSchema)
|
|
|
|
const blocksRefsSchema = z.discriminatedUnion("__typename", [
|
|
destinationOverviewPageCarouselCardsRef,
|
|
])
|
|
|
|
export const destinationOverviewPageRefsSchema = z.object({
|
|
destination_overview_page: z.object({
|
|
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
|
|
system: systemSchema,
|
|
}),
|
|
})
|