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 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 <Overview user={user} title={content.title} />
return <Overview user={user} title={props.title} />
case DynamicContentComponents.previous_stays:
return <PreviousStays {...componentProps} />
return <PreviousStays {...props} />
case DynamicContentComponents.soonest_stays:
return <SoonestStays {...componentProps} />
return <SoonestStays {...props} />
case DynamicContentComponents.upcoming_stays:
return <UpcomingStays {...componentProps} />
return <UpcomingStays {...props} />
case DynamicContentComponents.current_benefits:
return <CurrentBenefitsBlock {...componentProps} />
return <CurrentBenefitsBlock {...props} />
case DynamicContentComponents.next_benefits:
return <NextLevelBenefitsBlock {...componentProps} />
return <NextLevelBenefitsBlock {...props} />
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 (
<DynamicComponent
component={item.dynamic_content.component}
user={user}
lang={lang}
content={item.dynamic_content}
props={componentProps}
/>
)
case ContentEntries.AccountPageContentShortcuts:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,33 +19,33 @@ export enum ContentEntries {
AccountPageContentTextContent = "AccountPageContentTextContent",
}
export type Shortcut = {
type Shortcut = {
text: string
linkConnection: Edges<PageLink>
}
export type DynamicContent = {
type DynamicContent = {
component: DynamicContentComponents
title: string
preamble: string
title?: string
preamble?: string
link: { linkConnection: Edges<PageLink>; 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[]