feat: add shortcuts component to loyaltypage
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import JsonToHtml from "@/components/JsonToHtml"
|
import JsonToHtml from "@/components/JsonToHtml"
|
||||||
import DynamicContentBlock from "@/components/Loyalty/Blocks/DynamicContent"
|
import DynamicContentBlock from "@/components/Loyalty/Blocks/DynamicContent"
|
||||||
|
import Shortcuts from "@/components/MyPages/Blocks/Shortcuts"
|
||||||
|
|
||||||
import CardGrid from "./CardGrid"
|
import CardGrid from "./CardGrid"
|
||||||
|
|
||||||
@@ -22,6 +23,14 @@ export function Blocks({ blocks }: BlocksProps) {
|
|||||||
)
|
)
|
||||||
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent:
|
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent:
|
||||||
return <DynamicContentBlock dynamicContent={block.dynamic_content} />
|
return <DynamicContentBlock dynamicContent={block.dynamic_content} />
|
||||||
|
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts:
|
||||||
|
return (
|
||||||
|
<Shortcuts
|
||||||
|
shortcuts={block.shortcuts.shortcuts}
|
||||||
|
title={block.shortcuts.title}
|
||||||
|
subtitle={block.shortcuts.preamble}
|
||||||
|
/>
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,27 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
|
|||||||
items {
|
items {
|
||||||
blocks {
|
blocks {
|
||||||
__typename
|
__typename
|
||||||
|
... on LoyaltyPageBlocksShortcuts {
|
||||||
|
shortcuts {
|
||||||
|
title
|
||||||
|
preamble
|
||||||
|
shortcuts {
|
||||||
|
text
|
||||||
|
open_in_new_tab
|
||||||
|
linkConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
__typename
|
||||||
|
...AccountPageLink
|
||||||
|
...LoyaltyPageLink
|
||||||
|
...ContentPageLink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
... on LoyaltyPageBlocksDynamicContent {
|
... on LoyaltyPageBlocksDynamicContent {
|
||||||
dynamic_content {
|
dynamic_content {
|
||||||
title
|
title
|
||||||
@@ -58,6 +79,8 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
|
|||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
...Image
|
...Image
|
||||||
|
...LoyaltyPageLink
|
||||||
|
...ContentPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalCount
|
totalCount
|
||||||
@@ -93,6 +116,8 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
|
|||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
...Image
|
...Image
|
||||||
|
...LoyaltyPageLink
|
||||||
|
...ContentPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalCount
|
totalCount
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import { RTEDocument } from "@/types/rte/node"
|
|||||||
|
|
||||||
const accountPageShortcuts = z.object({
|
const accountPageShortcuts = z.object({
|
||||||
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
||||||
title: z.string().optional(),
|
|
||||||
preamble: z.string().optional(),
|
|
||||||
shortcuts: z.object({
|
shortcuts: z.object({
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
preamble: z.string().optional(),
|
preamble: z.string().optional(),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { Lang } from "@/constants/languages"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
JoinLoyaltyContactTypenameEnum,
|
JoinLoyaltyContactTypenameEnum,
|
||||||
LoyaltyBlocksTypenameEnum,
|
LoyaltyBlocksTypenameEnum,
|
||||||
@@ -55,6 +57,7 @@ const loyaltyPageDynamicContent = z.object({
|
|||||||
node: z.object({
|
node: z.object({
|
||||||
system: z.object({
|
system: z.object({
|
||||||
uid: z.string(),
|
uid: z.string(),
|
||||||
|
locale: z.nativeEnum(Lang),
|
||||||
}),
|
}),
|
||||||
url: z.string(),
|
url: z.string(),
|
||||||
title: 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({
|
const loyaltyPageBlockTextContent = z.object({
|
||||||
__typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent),
|
__typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent),
|
||||||
content: z.object({
|
content: z.object({
|
||||||
@@ -84,6 +121,7 @@ const loyaltyPageBlockItem = z.discriminatedUnion("__typename", [
|
|||||||
loyaltyPageBlockCardGrid,
|
loyaltyPageBlockCardGrid,
|
||||||
loyaltyPageDynamicContent,
|
loyaltyPageDynamicContent,
|
||||||
loyaltyPageBlockTextContent,
|
loyaltyPageBlockTextContent,
|
||||||
|
loyaltyPageShortcuts,
|
||||||
])
|
])
|
||||||
|
|
||||||
const loyaltyPageSidebarTextContent = z.object({
|
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
|
// Sidebar block types
|
||||||
type SidebarContentRaw = z.infer<typeof loyaltyPageSidebarTextContent>
|
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 JoinLoyaltyContact = z.infer<typeof loyaltyPageJoinLoyaltyContact>
|
||||||
export type Sidebar = JoinLoyaltyContact | RteSidebarContent
|
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]
|
type LoyaltyPageRaw = LoyaltyPageDataRaw["all_loyalty_page"]["items"][0]
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import { badRequestError } from "@/server/errors/trpc"
|
|||||||
import { publicProcedure, router } from "@/server/trpc"
|
import { publicProcedure, router } from "@/server/trpc"
|
||||||
|
|
||||||
import { getLoyaltyPageInput } from "./input"
|
import { getLoyaltyPageInput } from "./input"
|
||||||
import { type LoyaltyPage, validateLoyaltyPageSchema } from "./output"
|
import {
|
||||||
|
type LoyaltyPage,
|
||||||
|
type LoyaltyPageDataRaw,
|
||||||
|
validateLoyaltyPageSchema,
|
||||||
|
} from "./output"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
LoyaltyBlocksTypenameEnum,
|
LoyaltyBlocksTypenameEnum,
|
||||||
@@ -17,7 +21,7 @@ import { RTEDocument } from "@/types/rte/node"
|
|||||||
export const loyaltyPageQueryRouter = router({
|
export const loyaltyPageQueryRouter = router({
|
||||||
get: publicProcedure.input(getLoyaltyPageInput).query(async ({ input }) => {
|
get: publicProcedure.input(getLoyaltyPageInput).query(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
const loyaltyPageRes = await request<LoyaltyPage>(GetLoyaltyPage, {
|
const loyaltyPageRes = await request<LoyaltyPageDataRaw>(GetLoyaltyPage, {
|
||||||
locale: input.locale,
|
locale: input.locale,
|
||||||
url: input.href,
|
url: input.href,
|
||||||
})
|
})
|
||||||
@@ -108,6 +112,22 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts:
|
||||||
|
return {
|
||||||
|
...block,
|
||||||
|
shortcuts: {
|
||||||
|
...block.shortcuts,
|
||||||
|
shortcuts: block.shortcuts.shortcuts.map((shortcut) => ({
|
||||||
|
text: shortcut.text,
|
||||||
|
openInNewTab: shortcut.open_in_new_tab,
|
||||||
|
...shortcut.linkConnection.edges[0].node,
|
||||||
|
url:
|
||||||
|
shortcut.linkConnection.edges[0].node.web
|
||||||
|
?.original_url ||
|
||||||
|
`/${shortcut.linkConnection.edges[0].node.system.locale}${shortcut.linkConnection.edges[0].node.url}`,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ export enum LoyaltyBlocksTypenameEnum {
|
|||||||
LoyaltyPageBlocksDynamicContent = "LoyaltyPageBlocksDynamicContent",
|
LoyaltyPageBlocksDynamicContent = "LoyaltyPageBlocksDynamicContent",
|
||||||
LoyaltyPageBlocksCardGrid = "LoyaltyPageBlocksCardGrid",
|
LoyaltyPageBlocksCardGrid = "LoyaltyPageBlocksCardGrid",
|
||||||
LoyaltyPageBlocksContent = "LoyaltyPageBlocksContent",
|
LoyaltyPageBlocksContent = "LoyaltyPageBlocksContent",
|
||||||
|
LoyaltyPageBlocksShortcuts = "LoyaltyPageBlocksShortcuts",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user