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