chore: organize types
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
import {
|
||||
ContentEntries,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
} from "@/types/components/myPages/myPage/enums"
|
||||
|
||||
function DynamicComponent({ component, props }: AccountPageContentProps) {
|
||||
switch (component) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import { z } from "zod"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import {
|
||||
ContentEntries,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
} from "@/types/components/myPages/myPage/enums"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
@@ -97,7 +97,10 @@ export type RteTextContent = Omit<TextContentRaw, "text_content"> & {
|
||||
}
|
||||
}
|
||||
|
||||
type AccountPageContentItem = DynamicContentRaw | ShortcutsRaw | RteTextContent
|
||||
export type AccountPageContentItem =
|
||||
| DynamicContentRaw
|
||||
| ShortcutsRaw
|
||||
| RteTextContent
|
||||
|
||||
const accountPageContentItem = z.discriminatedUnion("__typename", [
|
||||
accountPageShortcuts,
|
||||
|
||||
@@ -6,18 +6,15 @@ import { publicProcedure, router } from "@/server/trpc"
|
||||
import { getAccountPageInput } from "./input"
|
||||
import { type AccountPage, validateAccountPageSchema } from "./output"
|
||||
|
||||
import { ContentEntries } from "@/types/components/myPages/myPage/enums"
|
||||
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({
|
||||
get: publicProcedure.input(getAccountPageInput).query(async ({ input }) => {
|
||||
try {
|
||||
const response = await request<GetAccountPageData>(GetAccountPage, {
|
||||
const response = await request<AccountPage>(GetAccountPage, {
|
||||
locale: input.lang,
|
||||
url: input.url,
|
||||
})
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { AccountPageContentItem } from "@/server/routers/contentstack/accountPage/output"
|
||||
|
||||
import {
|
||||
AccountPageContentItem,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
import { DynamicContentComponents } from "@/types/components/myPages/myPage/enums"
|
||||
|
||||
export type AccountPageContentProps = {
|
||||
component: DynamicContentComponents
|
||||
|
||||
14
types/components/myPages/myPage/enums.ts
Normal file
14
types/components/myPages/myPage/enums.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export enum DynamicContentComponents {
|
||||
membership_overview = "membership_overview",
|
||||
soonest_stays = "soonest_stays",
|
||||
previous_stays = "previous_stays",
|
||||
upcoming_stays = "upcoming_stays",
|
||||
current_benefits = "current_benefits",
|
||||
next_benefits = "next_benefits",
|
||||
}
|
||||
|
||||
export enum ContentEntries {
|
||||
AccountPageContentDynamicContent = "AccountPageContentDynamicContent",
|
||||
AccountPageContentShortcuts = "AccountPageContentShortcuts",
|
||||
AccountPageContentTextContent = "AccountPageContentTextContent",
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
import { Embeds } from "../embeds"
|
||||
import { AllRequestResponse } from "../utils/all"
|
||||
import { PageLink } from "../utils/pageLink"
|
||||
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
import type { Edges } from "../utils/edges"
|
||||
import type { Typename } from "../utils/typename"
|
||||
|
||||
export enum DynamicContentComponents {
|
||||
membership_overview = "membership_overview",
|
||||
soonest_stays = "soonest_stays",
|
||||
previous_stays = "previous_stays",
|
||||
upcoming_stays = "upcoming_stays",
|
||||
current_benefits = "current_benefits",
|
||||
next_benefits = "next_benefits",
|
||||
}
|
||||
|
||||
export enum ContentEntries {
|
||||
AccountPageContentDynamicContent = "AccountPageContentDynamicContent",
|
||||
AccountPageContentShortcuts = "AccountPageContentShortcuts",
|
||||
AccountPageContentTextContent = "AccountPageContentTextContent",
|
||||
}
|
||||
|
||||
type Shortcut = {
|
||||
linkConnection: Edges<PageLink>
|
||||
open_in_new_tab: boolean
|
||||
text?: string
|
||||
}
|
||||
|
||||
type DynamicContent = {
|
||||
component: DynamicContentComponents
|
||||
title?: string
|
||||
preamble?: string
|
||||
link: { linkConnection: Edges<PageLink>; link_text: string }
|
||||
}
|
||||
|
||||
type AccountPageDynamicContent = Typename<
|
||||
{ dynamic_content: DynamicContent },
|
||||
ContentEntries.AccountPageContentDynamicContent
|
||||
>
|
||||
|
||||
type AccountPageContentShortcuts = Typename<
|
||||
{
|
||||
shortcuts: { title?: string; preamble?: string; shortcuts: Shortcut[] }
|
||||
},
|
||||
ContentEntries.AccountPageContentShortcuts
|
||||
>
|
||||
|
||||
type AccountPageContentTextContent = Typename<
|
||||
{
|
||||
text_content: {
|
||||
content: {
|
||||
json: RTEDocument
|
||||
embedded_itemsConnection: Edges<Embeds>
|
||||
}
|
||||
}
|
||||
},
|
||||
ContentEntries.AccountPageContentTextContent
|
||||
>
|
||||
|
||||
export type AccountPageContentItem =
|
||||
| AccountPageDynamicContent
|
||||
| AccountPageContentShortcuts
|
||||
| AccountPageContentTextContent
|
||||
|
||||
type AccountPage = {
|
||||
url: string
|
||||
title: string
|
||||
content: AccountPageContentItem[]
|
||||
}
|
||||
|
||||
export type GetAccountPageData = {
|
||||
all_account_page: AllRequestResponse<AccountPage>
|
||||
}
|
||||
Reference in New Issue
Block a user