fix: align typings with loyalty-page branch
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import JsonToHtml from "@/components/JsonToHtml"
|
||||
import { renderOptions } from "@/components/JsonToHtml/renderOptions"
|
||||
import CurrentBenefitsBlock from "@/components/MyPages/Blocks/Benefits/CurrentLevel"
|
||||
import NextLevelBenefitsBlock from "@/components/MyPages/Blocks/Benefits/NextLevel"
|
||||
import Overview from "@/components/MyPages/Blocks/Overview"
|
||||
@@ -83,9 +82,10 @@ export default function Content({ lang, content }: ContentProps) {
|
||||
return (
|
||||
<section>
|
||||
<JsonToHtml
|
||||
embeds={[]}
|
||||
embeds={
|
||||
item.text_content.content.embedded_itemsConnection.edges
|
||||
}
|
||||
nodes={item.text_content.content.json.children}
|
||||
renderOptions={renderOptions}
|
||||
/>
|
||||
</section>
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ fragment AccountPageContentDynamicContent on AccountPageContentDynamicContent {
|
||||
link {
|
||||
link_text
|
||||
linkConnection {
|
||||
totalCount
|
||||
edges {
|
||||
node {
|
||||
...LoyaltyPageLink
|
||||
|
||||
@@ -18,6 +18,7 @@ fragment AccountPageContentShortcuts on AccountPageContentShortcuts {
|
||||
...ContentPageLink
|
||||
}
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
#import "../../Image.graphql"
|
||||
|
||||
fragment AccountPageContentTextContent on AccountPageContentTextContent {
|
||||
text_content {
|
||||
content {
|
||||
embedded_itemsConnection {
|
||||
totalCount
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
...Image
|
||||
}
|
||||
}
|
||||
}
|
||||
json
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import {
|
||||
ContentEntries,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
const accountPageShortcuts = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
||||
@@ -20,13 +25,14 @@ const accountPageShortcuts = z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
locale: z.nativeEnum(Lang),
|
||||
}),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
text: z.string().optional(),
|
||||
open_in_new_tab: z.boolean(),
|
||||
@@ -41,24 +47,25 @@ const accountPageDynamicContent = z.object({
|
||||
title: z.string().optional(),
|
||||
preamble: z.string().optional(),
|
||||
component: z.nativeEnum(DynamicContentComponents),
|
||||
link: z
|
||||
.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
}),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
link: z.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.nativeEnum(Lang),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
link_text: z.string(),
|
||||
}),
|
||||
// .optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -75,11 +82,32 @@ const accountPageTextContent = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentTextContent),
|
||||
text_content: z.object({
|
||||
content: z.object({
|
||||
json: jsonSchema,
|
||||
json: z.any(),
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(z.any()),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
type TextContentRaw = z.infer<typeof accountPageTextContent>
|
||||
|
||||
type DynamicContentRaw = z.infer<typeof accountPageDynamicContent>
|
||||
|
||||
type ShortcutsRaw = z.infer<typeof accountPageShortcuts>
|
||||
|
||||
export type RteTextContent = Omit<TextContentRaw, "text_content"> & {
|
||||
text_content: {
|
||||
content: {
|
||||
json: RTEDocument
|
||||
embedded_itemsConnection: Edges<Embeds>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type AccountPageContentItem = DynamicContentRaw | ShortcutsRaw | RteTextContent
|
||||
|
||||
const accountPageContentItem = z.discriminatedUnion("__typename", [
|
||||
accountPageShortcuts,
|
||||
accountPageDynamicContent,
|
||||
@@ -120,3 +148,13 @@ export const validateAccountPageBenefitsSchema = z.object({
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
type AccountPageDataRaw = z.infer<typeof validateAccountPageOverviewSchema>
|
||||
|
||||
type AccountPageRaw = AccountPageDataRaw["all_account_page"]["items"][0]
|
||||
|
||||
export type AccountPage = Omit<AccountPageRaw, "content"> & {
|
||||
url: string
|
||||
title: string
|
||||
content: AccountPageContentItem[]
|
||||
}
|
||||
|
||||
@@ -4,9 +4,15 @@ import { badRequestError, internalServerError } from "@/server/errors/trpc"
|
||||
import { publicProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { getAccountPageInput } from "./input"
|
||||
import { validateAccountPageSchema } from "./output"
|
||||
import { type AccountPage, validateAccountPageSchema } from "./output"
|
||||
|
||||
import type { GetAccountPageData } from "@/types/requests/myPages/accountpage"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import {
|
||||
ContentEntries,
|
||||
GetAccountPageData,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
export const accountPageQueryRouter = router({
|
||||
getOverview: publicProcedure
|
||||
@@ -30,8 +36,36 @@ export const accountPageQueryRouter = router({
|
||||
if (!validatedAccountPage.success) {
|
||||
throw badRequestError()
|
||||
}
|
||||
// TODO: Make returned data nicer
|
||||
const content =
|
||||
validatedAccountPage.data.all_account_page.items[0].content.map(
|
||||
(block) => {
|
||||
switch (block.__typename) {
|
||||
case ContentEntries.AccountPageContentDynamicContent:
|
||||
case ContentEntries.AccountPageContentShortcuts:
|
||||
return block
|
||||
case ContentEntries.AccountPageContentTextContent:
|
||||
return {
|
||||
...block,
|
||||
text_content: {
|
||||
content: {
|
||||
json: block.text_content.content.json as RTEDocument,
|
||||
embedded_itemsConnection: block.text_content.content
|
||||
.embedded_itemsConnection as Edges<Embeds>,
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return response.data.all_account_page.items[0]
|
||||
const accountPage = {
|
||||
...validatedAccountPage.data.all_account_page.items[0],
|
||||
content,
|
||||
} as AccountPage
|
||||
return accountPage
|
||||
} catch (error) {
|
||||
console.info(`Get Account Page Overview Error`)
|
||||
console.error(error)
|
||||
@@ -60,7 +94,35 @@ export const accountPageQueryRouter = router({
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
return response.data.all_account_page.items[0]
|
||||
const content =
|
||||
validatedAccountPage.data.all_account_page.items[0].content.map(
|
||||
(block) => {
|
||||
switch (block.__typename) {
|
||||
case ContentEntries.AccountPageContentDynamicContent:
|
||||
case ContentEntries.AccountPageContentShortcuts:
|
||||
return block
|
||||
case ContentEntries.AccountPageContentTextContent:
|
||||
return {
|
||||
...block,
|
||||
text_content: {
|
||||
content: {
|
||||
json: block.text_content.content.json as RTEDocument,
|
||||
embedded_itemsConnection: block.text_content.content
|
||||
.embedded_itemsConnection as Edges<Embeds>,
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const accountPage = {
|
||||
...validatedAccountPage.data.all_account_page.items[0],
|
||||
content,
|
||||
} as AccountPage
|
||||
return accountPage
|
||||
} catch (error) {
|
||||
console.info(`Get Account Page Benefits Error`)
|
||||
console.error(error)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Embeds } from "../embeds"
|
||||
import { AllRequestResponse } from "../utils/all"
|
||||
import { PageLink } from "../utils/pageLink"
|
||||
|
||||
@@ -23,7 +24,7 @@ export enum ContentEntries {
|
||||
type Shortcut = {
|
||||
linkConnection: Edges<PageLink>
|
||||
open_in_new_tab: boolean
|
||||
text: string
|
||||
text?: string
|
||||
}
|
||||
|
||||
type DynamicContent = {
|
||||
@@ -52,6 +53,7 @@ type AccountPageContentTextContent = Typename<
|
||||
text_content: {
|
||||
content: {
|
||||
json: RTEDocument
|
||||
embedded_itemsConnection: Edges<Embeds>
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user