Merge branch 'develop' into feature/tracking
This commit is contained in:
@@ -321,7 +321,7 @@ const validateInternalLink = z
|
||||
const lang = node.system.locale
|
||||
|
||||
return {
|
||||
url: originalUrl ?? removeMultipleSlashes(`/${lang}/${url}`),
|
||||
url: originalUrl || removeMultipleSlashes(`/${lang}/${url}`),
|
||||
title: node.title,
|
||||
}
|
||||
})
|
||||
@@ -339,14 +339,18 @@ export const validateLinkItem = z
|
||||
url: data.pageConnection?.url ?? data.link?.href ?? "",
|
||||
title: data?.title ?? data.link?.title,
|
||||
openInNewTab: data.open_in_new_tab,
|
||||
isExternal: !!data.link?.href,
|
||||
isExternal: !data.pageConnection?.url,
|
||||
}
|
||||
})
|
||||
|
||||
const validateLinks = z
|
||||
.array(validateLinkItem)
|
||||
.transform((data) => data.filter((item) => item.url))
|
||||
|
||||
export const validateSecondaryLinks = z.array(
|
||||
z.object({
|
||||
title: z.string(),
|
||||
links: z.array(validateLinkItem),
|
||||
links: validateLinks,
|
||||
})
|
||||
)
|
||||
|
||||
@@ -362,7 +366,7 @@ export const validateFooterConfigSchema = z
|
||||
all_footer: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
main_links: z.array(validateLinkItem),
|
||||
main_links: validateLinks,
|
||||
app_downloads: z.object({
|
||||
title: z.string(),
|
||||
links: validateLinksWithType,
|
||||
@@ -371,7 +375,7 @@ export const validateFooterConfigSchema = z
|
||||
social_media: z.object({
|
||||
links: validateLinksWithType,
|
||||
}),
|
||||
tertiary_links: z.array(validateLinkItem),
|
||||
tertiary_links: validateLinks,
|
||||
})
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { GetContentPage } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
||||
import {
|
||||
GetContentPage,
|
||||
GetContentPageBlocks,
|
||||
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
@@ -40,18 +43,38 @@ export const contentPageQueryRouter = router({
|
||||
})
|
||||
)
|
||||
|
||||
const response = await request<GetContentPageSchema>(
|
||||
GetContentPage,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags,
|
||||
},
|
||||
}
|
||||
)
|
||||
const [mainResponse, blocksResponse] = await Promise.all([
|
||||
request<GetContentPageSchema>(
|
||||
GetContentPage,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags,
|
||||
},
|
||||
}
|
||||
),
|
||||
request<GetContentPageSchema>(
|
||||
GetContentPageBlocks,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags,
|
||||
},
|
||||
}
|
||||
),
|
||||
])
|
||||
|
||||
const contentPage = contentPageSchema.safeParse(response.data)
|
||||
const responseData = {
|
||||
...mainResponse.data,
|
||||
content_page: {
|
||||
...mainResponse.data.content_page,
|
||||
blocks: blocksResponse.data.content_page.blocks,
|
||||
},
|
||||
}
|
||||
|
||||
const contentPage = contentPageSchema.safeParse(responseData)
|
||||
|
||||
if (!contentPage.success) {
|
||||
console.error(
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
||||
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
import { imageSchema } from "./image"
|
||||
import { imageContainerSchema } from "./imageContainer"
|
||||
|
||||
import { BlocksEnums } from "@/types/enums/blocks"
|
||||
import { CardsGridEnum } from "@/types/enums/cardsGrid"
|
||||
import { CardsGridEnum, CardsGridLayoutEnum } from "@/types/enums/cardsGrid"
|
||||
|
||||
export const cardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsGridEnum.cards.Card),
|
||||
@@ -49,9 +53,43 @@ export const teaserCardBlockSchema = z.object({
|
||||
has_primary_button: z.boolean().default(false),
|
||||
has_secondary_button: z.boolean().default(false),
|
||||
has_sidepeek_button: z.boolean().default(false),
|
||||
side_peek_button: z
|
||||
sidepeek_button: z
|
||||
.object({
|
||||
title: z.string().optional().default(""),
|
||||
call_to_action_text: z.string().optional().default(""),
|
||||
})
|
||||
.optional(),
|
||||
sidepeek_content: z
|
||||
.object({
|
||||
heading: z.string(),
|
||||
content: z.object({
|
||||
json: z.any(),
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z
|
||||
.discriminatedUnion("__typename", [
|
||||
imageContainerSchema,
|
||||
imageSchema,
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.hotelPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
if (link) {
|
||||
return link
|
||||
}
|
||||
return data
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
primary_button: buttonSchema,
|
||||
has_secondary_button: z.boolean().default(false),
|
||||
secondary_button: buttonSchema,
|
||||
})
|
||||
.optional(),
|
||||
system: systemSchema,
|
||||
@@ -68,8 +106,9 @@ export function transformTeaserCardBlock(
|
||||
secondaryButton: card.has_secondary_button
|
||||
? card.secondary_button
|
||||
: undefined,
|
||||
sidePeekButton: card.has_sidepeek_button
|
||||
? card.side_peek_button
|
||||
sidePeekButton: card.has_sidepeek_button ? card.sidepeek_button : undefined,
|
||||
sidePeekContent: card.has_sidepeek_button
|
||||
? card.sidepeek_content
|
||||
: undefined,
|
||||
image: card.image,
|
||||
system: card.system,
|
||||
@@ -105,7 +144,7 @@ export const cardsGridSchema = z.object({
|
||||
})
|
||||
),
|
||||
}),
|
||||
layout: z.enum(["twoColumnGrid", "threeColumnGrid", "twoPlusOne"]),
|
||||
layout: z.nativeEnum(CardsGridLayoutEnum),
|
||||
preamble: z.string().optional().default(""),
|
||||
theme: z.enum(["one", "two", "three"]).nullable(),
|
||||
title: z.string().optional().default(""),
|
||||
|
||||
@@ -9,49 +9,57 @@ export const shortcutsSchema = z.object({
|
||||
.literal(BlocksEnums.block.Shortcuts)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.Shortcuts),
|
||||
shortcuts: z.object({
|
||||
subtitle: z.string().nullable(),
|
||||
title: z.string().nullable(),
|
||||
shortcuts: z
|
||||
.array(
|
||||
z.object({
|
||||
open_in_new_tab: z.boolean(),
|
||||
text: z.string().optional().default(""),
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z
|
||||
.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
if (link) {
|
||||
return link
|
||||
}
|
||||
return data
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.transform((data) => {
|
||||
return data
|
||||
.filter((node) => node.linkConnection.edges.length)
|
||||
.map((node) => {
|
||||
const link = node.linkConnection.edges[0].node
|
||||
return {
|
||||
openInNewTab: node.open_in_new_tab,
|
||||
text: node.text,
|
||||
title: link.title,
|
||||
url: link.url,
|
||||
}
|
||||
shortcuts: z
|
||||
.object({
|
||||
subtitle: z.string().nullable(),
|
||||
title: z.string().nullable(),
|
||||
two_column_list: z.boolean().nullable().default(false),
|
||||
shortcuts: z
|
||||
.array(
|
||||
z.object({
|
||||
open_in_new_tab: z.boolean(),
|
||||
text: z.string().optional().default(""),
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z
|
||||
.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
if (link) {
|
||||
return link
|
||||
}
|
||||
return data
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
}),
|
||||
}),
|
||||
)
|
||||
.transform((data) => {
|
||||
return data
|
||||
.filter((node) => node.linkConnection.edges.length)
|
||||
.map((node) => {
|
||||
const link = node.linkConnection.edges[0].node
|
||||
return {
|
||||
openInNewTab: node.open_in_new_tab,
|
||||
text: node.text,
|
||||
title: link.title,
|
||||
url: link.url,
|
||||
}
|
||||
})
|
||||
}),
|
||||
})
|
||||
.transform(({ two_column_list, ...rest }) => {
|
||||
return {
|
||||
...rest,
|
||||
hasTwoColumns: !!two_column_list,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const shortcutsRefsSchema = z.object({
|
||||
|
||||
@@ -20,6 +20,7 @@ export const buttonSchema = z
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
pageLinks.hotelPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
|
||||
Reference in New Issue
Block a user