chore: organize types

This commit is contained in:
Arvid Norlin
2024-05-02 10:52:05 +02:00
parent ec37ee0f1f
commit 58d2963d6a
6 changed files with 25 additions and 87 deletions

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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,
})

View File

@@ -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

View 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",
}

View File

@@ -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>
}