fix: validation for header

This commit is contained in:
Simon Emanuelsson
2024-09-22 21:22:21 +02:00
parent ac5e48357c
commit 68703d72e1
33 changed files with 453 additions and 404 deletions

View File

@@ -8,7 +8,7 @@ import { linkConnectionRefsSchema } from "./utils/linkConnection"
import { BlocksEnums } from "@/types/enums/blocks"
import { CardsGridEnum } from "@/types/enums/cardsGrid"
const cardBlockSchema = z.object({
export const cardBlockSchema = z.object({
__typename: z.literal(CardsGridEnum.cards.Card),
// JSON - ImageVault Image
background_image: tempImageVaultAssetSchema,
@@ -30,6 +30,29 @@ const cardBlockSchema = z.object({
title: z.string().optional(),
})
export function transformCardBlock(card: typeof cardBlockSchema._type) {
return {
__typename: card.__typename,
backgroundImage: card.background_image,
body_text: card.body_text,
heading: card.heading,
isContentCard: card.is_content_card,
primaryButton: card.has_primary_button ? card.primary_button : undefined,
scripted_top_title: card.scripted_top_title,
secondaryButton: card.has_secondary_button
? card.secondary_button
: undefined,
sidePeekButton:
card.has_sidepeek_button && card.sidepeek_button?.call_to_action_text
? {
title: card.sidepeek_button.call_to_action_text,
}
: undefined,
system: card.system,
title: card.title,
}
}
const loyaltyCardBlockSchema = z.object({
__typename: z.literal(CardsGridEnum.cards.LoyaltyCard),
body_text: z.string().optional(),
@@ -71,29 +94,7 @@ export const cardsGridSchema = z.object({
title: data.title,
cards: data.cardConnection.edges.map((card) => {
if (card.node.__typename === CardsGridEnum.cards.Card) {
return {
__typename: card.node.__typename,
backgroundImage: card.node.background_image,
body_text: card.node.body_text,
heading: card.node.heading,
isContentCard: card.node.is_content_card,
primaryButton: card.node.has_primary_button
? card.node.primary_button
: undefined,
scripted_top_title: card.node.scripted_top_title,
secondaryButton: card.node.has_secondary_button
? card.node.secondary_button
: undefined,
sidePeekButton:
card.node.has_sidepeek_button &&
card.node.sidepeek_button?.call_to_action_text
? {
title: card.node.sidepeek_button.call_to_action_text,
}
: undefined,
system: card.node.system,
title: card.node.title,
}
return transformCardBlock(card.node)
} else {
return {
__typename: card.node.__typename,
@@ -110,13 +111,24 @@ export const cardsGridSchema = z.object({
}),
})
const cardBlockRefsSchema = z.object({
export const cardBlockRefsSchema = z.object({
__typename: z.literal(CardsGridEnum.cards.Card),
primary_button: linkConnectionRefsSchema,
secondary_button: linkConnectionRefsSchema,
system: systemSchema,
})
export function transformCardBlockRefs(card: typeof cardBlockRefsSchema._type) {
const cards = [card.system]
if (card.primary_button) {
cards.push(card.primary_button)
}
if (card.secondary_button) {
cards.push(card.secondary_button)
}
return cards
}
const loyaltyCardBlockRefsSchema = z.object({
__typename: z.literal(CardsGridEnum.cards.LoyaltyCard),
link: linkConnectionRefsSchema,
@@ -141,14 +153,7 @@ export const cardGridRefsSchema = z.object({
return data.cardConnection.edges
.map(({ node }) => {
if (node.__typename === CardsGridEnum.cards.Card) {
const cards = [node.system]
if (node.primary_button) {
cards.push(node.primary_button)
}
if (node.secondary_button) {
cards.push(node.secondary_button)
}
return cards
return transformCardBlockRefs(node)
} else {
const loyaltyCards = [node.system]
if (node.link) {

View File

@@ -46,7 +46,7 @@ export const hotelPageSchema = z
.object({
__typename: z.literal(ContentEnum.blocks.HotelPage),
})
.merge(extendedPageLinkSchema)
.merge(pageLinkSchema)
export const hotelPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.HotelPage),