chore: clean up typings

This commit is contained in:
Arvid Norlin
2024-04-23 15:39:23 +02:00
parent b12ccfafef
commit 1e8f23de38
8 changed files with 71 additions and 66 deletions

View File

@@ -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 CurrentBenefitsBlock from "@/components/MyPages/Blocks/Benefits/CurrentLevel"
import JsonToHtml from "@/components/JsonToHtml" import JsonToHtml from "@/components/JsonToHtml"
import NextLevelBenefitsBlock from "@/components/MyPages/Blocks/Benefits/NextLevel" 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 UpcomingStays from "@/components/MyPages/Blocks/Stays/Upcoming"
import SoonestStays from "@/components/MyPages/Blocks/Stays/Soonest" import SoonestStays from "@/components/MyPages/Blocks/Stays/Soonest"
import { renderOptions } from "@/components/JsonToHtml/renderOptions" import { renderOptions } from "@/components/JsonToHtml/renderOptions"
import { AccountPageContentProps } from "@/types/components/myPages/myPage/accountPage"
import PreviousStays from "../Blocks/Stays/Previous" import PreviousStays from "../Blocks/Stays/Previous"
function DynamicComponent({ user, lang, content }: AccountPageContentProps) { import {
const link = content.link.linkConnection.edges.length ContentEntries,
? { DynamicContentComponents,
href: content.link.linkConnection.edges[0].node.url, } from "@/types/requests/myPages/accountpage"
text: content.link.link_text, import {
} AccountPageContentProps,
: null ContentProps,
} from "@/types/components/myPages/myPage/accountPage"
const componentProps = { function DynamicComponent({ user, component, props }: AccountPageContentProps) {
lang, switch (component) {
title: content.title,
// TODO: rename preamble to subtitle in Contentstack
subtitle: content.preamble,
...link,
}
switch (content.component) {
case DynamicContentComponents.membership_overview: case DynamicContentComponents.membership_overview:
return <Overview user={user} title={content.title} /> return <Overview user={user} title={props.title} />
case DynamicContentComponents.previous_stays: case DynamicContentComponents.previous_stays:
return <PreviousStays {...componentProps} /> return <PreviousStays {...props} />
case DynamicContentComponents.soonest_stays: case DynamicContentComponents.soonest_stays:
return <SoonestStays {...componentProps} /> return <SoonestStays {...props} />
case DynamicContentComponents.upcoming_stays: case DynamicContentComponents.upcoming_stays:
return <UpcomingStays {...componentProps} /> return <UpcomingStays {...props} />
case DynamicContentComponents.current_benefits: case DynamicContentComponents.current_benefits:
return <CurrentBenefitsBlock {...componentProps} /> return <CurrentBenefitsBlock {...props} />
case DynamicContentComponents.next_benefits: case DynamicContentComponents.next_benefits:
return <NextLevelBenefitsBlock {...componentProps} /> return <NextLevelBenefitsBlock {...props} />
default: default:
return null return null
} }
} }
export default function Content({ export default function Content({ user, lang, content }: ContentProps) {
user,
lang,
content,
}: {
user: User
lang: Lang
content: AccountPageContentItem[]
}) {
return ( return (
<> <>
{content.map((item) => { {content.map((item) => {
switch (item.__typename) { switch (item.__typename) {
case ContentEntries.AccountPageContentDynamicContent: 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 ( return (
<DynamicComponent <DynamicComponent
component={item.dynamic_content.component}
user={user} user={user}
lang={lang} props={componentProps}
content={item.dynamic_content}
/> />
) )
case ContentEntries.AccountPageContentShortcuts: case ContentEntries.AccountPageContentShortcuts:

View File

@@ -11,9 +11,11 @@ export default function Overview({ user, title }: OverviewProps) {
return ( return (
<section className={styles.container}> <section className={styles.container}>
<header> <header>
<Title as="h3" level="h2" uppercase className={styles.title}> {title && (
{title} <Title as="h3" level="h2" uppercase className={styles.title}>
</Title> {title}
</Title>
)}
</header> </header>
<section className={styles.overview}> <section className={styles.overview}>
<Friend user={user} /> <Friend user={user} />

View File

@@ -1,7 +1,5 @@
"use client" "use client"
import { Lang } from "@/constants/languages"
import { _ } from "@/lib/translation"
import { trpc } from "@/lib/trpc/client" import { trpc } from "@/lib/trpc/client"
import Container from "../Container" import Container from "../Container"
@@ -16,7 +14,7 @@ import type { Page } from "@/types/components/myPages/myStays/page"
export default function PreviousStays({ export default function PreviousStays({
lang, lang,
title, title = "", // TODO: Should the title be optional?
subtitle, subtitle,
link, link,
}: AccountPageComponentProps) { }: AccountPageComponentProps) {

View File

@@ -10,7 +10,7 @@ import { AccountPageComponentProps } from "@/types/components/myPages/myPage/acc
export default async function UpcomingStays({ export default async function UpcomingStays({
lang, lang,
title, title = "", // TODO: Should this be optional?
subtitle, subtitle,
link, link,
}: AccountPageComponentProps) { }: AccountPageComponentProps) {

View File

@@ -16,7 +16,7 @@ import type { Page } from "@/types/components/myPages/myStays/page"
export default function UpcomingStays({ export default function UpcomingStays({
lang, lang,
title, title = "", // TODO: Should this be optional?
subtitle, subtitle,
link, link,
}: AccountPageComponentProps) { }: AccountPageComponentProps) {

View File

@@ -1,16 +1,30 @@
import { Lang } from "@/constants/languages" 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" import { User } from "@/types/user"
export type AccountPageContentProps = { export type AccountPageContentProps = {
content: DynamicContent component: DynamicContentComponents
lang: Lang props: {
title?: string
subtitle?: string
link?: { href: string; text: string }
lang: Lang
}
user: User user: User
} }
export type AccountPageComponentProps = { export type AccountPageComponentProps = {
lang: Lang lang: Lang
title: string title?: string
subtitle?: string subtitle?: string
link?: { href: string; text: string } link?: { href: string; text: string }
} }
export type ContentProps = {
user: User
lang: Lang
content: AccountPageContentItem[]
}

View File

@@ -1,6 +1,6 @@
import type { User } from "@/types/user" import type { User } from "@/types/user"
export type OverviewProps = { export type OverviewProps = {
title: string title?: string
user: User user: User
} }

View File

@@ -19,33 +19,33 @@ export enum ContentEntries {
AccountPageContentTextContent = "AccountPageContentTextContent", AccountPageContentTextContent = "AccountPageContentTextContent",
} }
export type Shortcut = { type Shortcut = {
text: string text: string
linkConnection: Edges<PageLink> linkConnection: Edges<PageLink>
} }
export type DynamicContent = { type DynamicContent = {
component: DynamicContentComponents component: DynamicContentComponents
title: string title?: string
preamble: string preamble?: string
link: { linkConnection: Edges<PageLink>; link_text: string } link: { linkConnection: Edges<PageLink>; link_text: string }
} }
export type AccountPageDynamicContent = Typename< type AccountPageDynamicContent = Typename<
{ dynamic_content: DynamicContent }, { dynamic_content: DynamicContent },
ContentEntries.AccountPageContentDynamicContent ContentEntries.AccountPageContentDynamicContent
> >
export type AccountPageContentShortcuts = Typename< type AccountPageContentShortcuts = Typename<
{ {
title: string title?: string
preamble: string preamble?: string
shortcuts: { shortcuts: Shortcut[] } shortcuts: { shortcuts: Shortcut[] }
}, },
ContentEntries.AccountPageContentShortcuts ContentEntries.AccountPageContentShortcuts
> >
export type AccountPageContentTextContent = Typename< type AccountPageContentTextContent = Typename<
{ {
text_content: { text_content: {
content: { content: {
@@ -61,7 +61,7 @@ export type AccountPageContentItem =
| AccountPageContentShortcuts | AccountPageContentShortcuts
| AccountPageContentTextContent | AccountPageContentTextContent
export type AccountPage = { type AccountPage = {
url: string url: string
title: string title: string
content: AccountPageContentItem[] content: AccountPageContentItem[]