feat: add shortcuts component to loyaltypage

This commit is contained in:
Christel Westerberg
2024-05-06 11:11:02 +02:00
parent bfaacd7b5d
commit 2a46fe6572
6 changed files with 111 additions and 6 deletions
@@ -1,5 +1,7 @@
import { z } from "zod"
import { Lang } from "@/constants/languages"
import {
JoinLoyaltyContactTypenameEnum,
LoyaltyBlocksTypenameEnum,
@@ -55,6 +57,7 @@ const loyaltyPageDynamicContent = z.object({
node: z.object({
system: z.object({
uid: z.string(),
locale: z.nativeEnum(Lang),
}),
url: z.string(),
title: z.string(),
@@ -67,6 +70,40 @@ const loyaltyPageDynamicContent = z.object({
}),
})
const loyaltyPageShortcuts = z.object({
__typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts),
shortcuts: z.object({
title: z.string().optional(),
preamble: z.string().optional(),
shortcuts: z.array(
z.object({
linkConnection: z.object({
edges: z.array(
z.object({
node: z.object({
system: z.object({
uid: z.string(),
locale: z.nativeEnum(Lang),
}),
url: z.string(),
web: z
.object({
original_url: z.string(),
})
.optional(),
title: z.string(),
}),
})
),
totalCount: z.number(),
}),
text: z.string().optional(),
open_in_new_tab: z.boolean(),
})
),
}),
})
const loyaltyPageBlockTextContent = z.object({
__typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent),
content: z.object({
@@ -84,6 +121,7 @@ const loyaltyPageBlockItem = z.discriminatedUnion("__typename", [
loyaltyPageBlockCardGrid,
loyaltyPageDynamicContent,
loyaltyPageBlockTextContent,
loyaltyPageShortcuts,
])
const loyaltyPageSidebarTextContent = z.object({
@@ -182,7 +220,21 @@ export interface RteBlockContent extends BlockContentRaw {
}
}
}
export type Block = CardGrid | RteBlockContent | DynamicContent
type ShortcutsRaw = z.infer<typeof loyaltyPageShortcuts>
export type Shortcuts = Omit<ShortcutsRaw, "shortcuts"> & {
shortcuts: Omit<ShortcutsRaw["shortcuts"], "shortcuts"> & {
shortcuts: {
text?: string
openInNewTab: boolean
url: string
title: string
}[]
}
}
export type Block = CardGrid | RteBlockContent | DynamicContent | Shortcuts
// Sidebar block types
type SidebarContentRaw = z.infer<typeof loyaltyPageSidebarTextContent>
@@ -198,7 +250,7 @@ export type RteSidebarContent = Omit<SidebarContentRaw, "content"> & {
export type JoinLoyaltyContact = z.infer<typeof loyaltyPageJoinLoyaltyContact>
export type Sidebar = JoinLoyaltyContact | RteSidebarContent
type LoyaltyPageDataRaw = z.infer<typeof validateLoyaltyPageSchema>
export type LoyaltyPageDataRaw = z.infer<typeof validateLoyaltyPageSchema>
type LoyaltyPageRaw = LoyaltyPageDataRaw["all_loyalty_page"]["items"][0]