From 1e8f23de38fd1ce1acf72770950c949ebec69efe Mon Sep 17 00:00:00 2001 From: Arvid Norlin Date: Tue, 23 Apr 2024 15:39:23 +0200 Subject: [PATCH] chore: clean up typings --- components/MyPages/AccountPage/Content.tsx | 77 ++++++++----------- components/MyPages/Blocks/Overview/index.tsx | 8 +- .../MyPages/Blocks/Stays/Previous/index.tsx | 4 +- .../MyPages/Blocks/Stays/Soonest/index.tsx | 2 +- .../MyPages/Blocks/Stays/Upcoming/index.tsx | 2 +- .../components/myPages/myPage/accountPage.ts | 22 +++++- types/components/myPages/myPage/overview.ts | 2 +- types/requests/myPages/accountpage.ts | 20 ++--- 8 files changed, 71 insertions(+), 66 deletions(-) diff --git a/components/MyPages/AccountPage/Content.tsx b/components/MyPages/AccountPage/Content.tsx index 6be82bbfb..eac63803e 100644 --- a/components/MyPages/AccountPage/Content.tsx +++ b/components/MyPages/AccountPage/Content.tsx @@ -1,12 +1,3 @@ -import { Lang } from "@/constants/languages" - -import { - AccountPageContentItem, - ContentEntries, - DynamicContentComponents, -} from "@/types/requests/myPages/accountpage" -import { User } from "@/types/user" - import CurrentBenefitsBlock from "@/components/MyPages/Blocks/Benefits/CurrentLevel" import JsonToHtml from "@/components/JsonToHtml" import NextLevelBenefitsBlock from "@/components/MyPages/Blocks/Benefits/NextLevel" @@ -15,62 +6,62 @@ import Shortcuts from "@/components/MyPages/Blocks/Shortcuts" import UpcomingStays from "@/components/MyPages/Blocks/Stays/Upcoming" import SoonestStays from "@/components/MyPages/Blocks/Stays/Soonest" import { renderOptions } from "@/components/JsonToHtml/renderOptions" -import { AccountPageContentProps } from "@/types/components/myPages/myPage/accountPage" import PreviousStays from "../Blocks/Stays/Previous" -function DynamicComponent({ user, lang, content }: AccountPageContentProps) { - const link = content.link.linkConnection.edges.length - ? { - href: content.link.linkConnection.edges[0].node.url, - text: content.link.link_text, - } - : null +import { + ContentEntries, + DynamicContentComponents, +} from "@/types/requests/myPages/accountpage" +import { + AccountPageContentProps, + ContentProps, +} from "@/types/components/myPages/myPage/accountPage" - const componentProps = { - lang, - title: content.title, - // TODO: rename preamble to subtitle in Contentstack - subtitle: content.preamble, - ...link, - } - - switch (content.component) { +function DynamicComponent({ user, component, props }: AccountPageContentProps) { + switch (component) { case DynamicContentComponents.membership_overview: - return + return case DynamicContentComponents.previous_stays: - return + return case DynamicContentComponents.soonest_stays: - return + return case DynamicContentComponents.upcoming_stays: - return + return case DynamicContentComponents.current_benefits: - return + return case DynamicContentComponents.next_benefits: - return + return default: return null } } -export default function Content({ - user, - lang, - content, -}: { - user: User - lang: Lang - content: AccountPageContentItem[] -}) { +export default function Content({ user, lang, content }: ContentProps) { return ( <> {content.map((item) => { switch (item.__typename) { case ContentEntries.AccountPageContentDynamicContent: + const link = item.dynamic_content.link.linkConnection.edges.length + ? { + href: item.dynamic_content.link.linkConnection.edges[0].node + .url, + text: item.dynamic_content.link.link_text, + } + : null + + const componentProps = { + lang, + title: item.dynamic_content.title, + // TODO: rename preamble to subtitle in Contentstack + subtitle: item.dynamic_content.preamble, + ...link, + } return ( ) case ContentEntries.AccountPageContentShortcuts: diff --git a/components/MyPages/Blocks/Overview/index.tsx b/components/MyPages/Blocks/Overview/index.tsx index 1c7b73ed5..dc8f2dc30 100644 --- a/components/MyPages/Blocks/Overview/index.tsx +++ b/components/MyPages/Blocks/Overview/index.tsx @@ -11,9 +11,11 @@ export default function Overview({ user, title }: OverviewProps) { return (
- - {title} - + {title && ( + + {title} + + )}
diff --git a/components/MyPages/Blocks/Stays/Previous/index.tsx b/components/MyPages/Blocks/Stays/Previous/index.tsx index f284716c2..5665d3b31 100644 --- a/components/MyPages/Blocks/Stays/Previous/index.tsx +++ b/components/MyPages/Blocks/Stays/Previous/index.tsx @@ -1,7 +1,5 @@ "use client" -import { Lang } from "@/constants/languages" -import { _ } from "@/lib/translation" import { trpc } from "@/lib/trpc/client" import Container from "../Container" @@ -16,7 +14,7 @@ import type { Page } from "@/types/components/myPages/myStays/page" export default function PreviousStays({ lang, - title, + title = "", // TODO: Should the title be optional? subtitle, link, }: AccountPageComponentProps) { diff --git a/components/MyPages/Blocks/Stays/Soonest/index.tsx b/components/MyPages/Blocks/Stays/Soonest/index.tsx index 521bb84c4..8e5e7c8ed 100644 --- a/components/MyPages/Blocks/Stays/Soonest/index.tsx +++ b/components/MyPages/Blocks/Stays/Soonest/index.tsx @@ -10,7 +10,7 @@ import { AccountPageComponentProps } from "@/types/components/myPages/myPage/acc export default async function UpcomingStays({ lang, - title, + title = "", // TODO: Should this be optional? subtitle, link, }: AccountPageComponentProps) { diff --git a/components/MyPages/Blocks/Stays/Upcoming/index.tsx b/components/MyPages/Blocks/Stays/Upcoming/index.tsx index 05d4f3882..379d76fb3 100644 --- a/components/MyPages/Blocks/Stays/Upcoming/index.tsx +++ b/components/MyPages/Blocks/Stays/Upcoming/index.tsx @@ -16,7 +16,7 @@ import type { Page } from "@/types/components/myPages/myStays/page" export default function UpcomingStays({ lang, - title, + title = "", // TODO: Should this be optional? subtitle, link, }: AccountPageComponentProps) { diff --git a/types/components/myPages/myPage/accountPage.ts b/types/components/myPages/myPage/accountPage.ts index e1de317be..9229a3e70 100644 --- a/types/components/myPages/myPage/accountPage.ts +++ b/types/components/myPages/myPage/accountPage.ts @@ -1,16 +1,30 @@ import { Lang } from "@/constants/languages" -import { DynamicContent } from "@/types/requests/myPages/accountpage" +import { + AccountPageContentItem, + DynamicContentComponents, +} from "@/types/requests/myPages/accountpage" import { User } from "@/types/user" export type AccountPageContentProps = { - content: DynamicContent - lang: Lang + component: DynamicContentComponents + props: { + title?: string + subtitle?: string + link?: { href: string; text: string } + lang: Lang + } user: User } export type AccountPageComponentProps = { lang: Lang - title: string + title?: string subtitle?: string link?: { href: string; text: string } } + +export type ContentProps = { + user: User + lang: Lang + content: AccountPageContentItem[] +} diff --git a/types/components/myPages/myPage/overview.ts b/types/components/myPages/myPage/overview.ts index 7ad910578..e37d9ee0c 100644 --- a/types/components/myPages/myPage/overview.ts +++ b/types/components/myPages/myPage/overview.ts @@ -1,6 +1,6 @@ import type { User } from "@/types/user" export type OverviewProps = { - title: string + title?: string user: User } diff --git a/types/requests/myPages/accountpage.ts b/types/requests/myPages/accountpage.ts index 499a90e27..64c37c19b 100644 --- a/types/requests/myPages/accountpage.ts +++ b/types/requests/myPages/accountpage.ts @@ -19,33 +19,33 @@ export enum ContentEntries { AccountPageContentTextContent = "AccountPageContentTextContent", } -export type Shortcut = { +type Shortcut = { text: string linkConnection: Edges } -export type DynamicContent = { +type DynamicContent = { component: DynamicContentComponents - title: string - preamble: string + title?: string + preamble?: string link: { linkConnection: Edges; link_text: string } } -export type AccountPageDynamicContent = Typename< +type AccountPageDynamicContent = Typename< { dynamic_content: DynamicContent }, ContentEntries.AccountPageContentDynamicContent > -export type AccountPageContentShortcuts = Typename< +type AccountPageContentShortcuts = Typename< { - title: string - preamble: string + title?: string + preamble?: string shortcuts: { shortcuts: Shortcut[] } }, ContentEntries.AccountPageContentShortcuts > -export type AccountPageContentTextContent = Typename< +type AccountPageContentTextContent = Typename< { text_content: { content: { @@ -61,7 +61,7 @@ export type AccountPageContentItem = | AccountPageContentShortcuts | AccountPageContentTextContent -export type AccountPage = { +type AccountPage = { url: string title: string content: AccountPageContentItem[]