Merged in feat/SW-1443-carousel-destination-overview-page (pull request #1289)
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)
This commit is contained in:
@@ -1,12 +1,33 @@
|
||||
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(),
|
||||
@@ -41,8 +62,21 @@ export const countryPageUrlSchema = z
|
||||
)
|
||||
|
||||
/** 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,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -24,10 +24,8 @@ const carouselCardsWithFilters = z.object({
|
||||
enable_filters: z.literal(true),
|
||||
card_groups: z.array(
|
||||
z.object({
|
||||
filter_category: z.object({
|
||||
filter_identifier: z.nativeEnum(CarouselCardFilterEnum),
|
||||
filter_label: z.string(),
|
||||
}),
|
||||
filter_identifier: z.nativeEnum(CarouselCardFilterEnum),
|
||||
filter_label: z.string(),
|
||||
cardConnection: z.object({
|
||||
edges: z.array(z.object({ node: contentCardSchema })),
|
||||
}),
|
||||
@@ -40,10 +38,8 @@ const carouselCardsWithoutFilters = z.object({
|
||||
enable_filters: z.literal(false),
|
||||
card_groups: z.array(
|
||||
z.object({
|
||||
filter_category: z.object({
|
||||
filter_identifier: z.null(),
|
||||
filter_label: z.string(),
|
||||
}),
|
||||
filter_identifier: z.null(),
|
||||
filter_label: z.string(),
|
||||
cardConnection: z.object({
|
||||
edges: z.array(z.object({ node: contentCardSchema })),
|
||||
}),
|
||||
@@ -74,7 +70,6 @@ export const carouselCardsSchema = z.object({
|
||||
)
|
||||
)
|
||||
.filter((card): card is NonNullable<typeof card> => card !== null),
|
||||
defaultFilter: null,
|
||||
link: data.link
|
||||
? { href: data.link.href, text: data.link.title }
|
||||
: undefined,
|
||||
@@ -87,11 +82,11 @@ export const carouselCardsSchema = z.object({
|
||||
label: string
|
||||
}>
|
||||
>((acc, group) => {
|
||||
const identifier = group.filter_category.filter_identifier
|
||||
const identifier = group.filter_identifier
|
||||
if (!acc.some((category) => category.identifier === identifier)) {
|
||||
acc.push({
|
||||
identifier,
|
||||
label: group.filter_category.filter_label,
|
||||
label: group.filter_label,
|
||||
})
|
||||
}
|
||||
return acc
|
||||
@@ -107,11 +102,11 @@ export const carouselCardsSchema = z.object({
|
||||
.filter((card): card is NonNullable<typeof card> => card !== null)
|
||||
.map((card) => ({
|
||||
...card,
|
||||
filterId: group.filter_category.filter_identifier,
|
||||
filterId: group.filter_identifier,
|
||||
}))
|
||||
),
|
||||
defaultFilter:
|
||||
data.card_groups[0]?.filter_category.filter_identifier ??
|
||||
data.card_groups[0]?.filter_identifier ??
|
||||
filterCategories[0]?.identifier,
|
||||
link: data.link
|
||||
? { href: data.link.href, text: data.link.title }
|
||||
|
||||
Reference in New Issue
Block a user