feat: move overview page query to tRPC request
This commit is contained in:
73
components/MyPages/AccountPage/Content.tsx
Normal file
73
components/MyPages/AccountPage/Content.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
AccountPageContentItem,
|
||||
ContentEntries,
|
||||
DynamicContent,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
import { User } from "@/types/user"
|
||||
import Overview from "@/components/MyPages/Blocks/Overview"
|
||||
import Shortcuts from "@/components/MyPages/Blocks/Shortcuts"
|
||||
import UpcomingStays from "@/components/MyPages/Blocks/UpcomingStays"
|
||||
|
||||
function DynamicComponent({
|
||||
user,
|
||||
lang,
|
||||
content,
|
||||
}: {
|
||||
content: DynamicContent
|
||||
lang: Lang
|
||||
user: User
|
||||
}) {
|
||||
switch (content.component) {
|
||||
case DynamicContentComponents.membership_overview:
|
||||
return <Overview user={user} />
|
||||
case DynamicContentComponents.benefits:
|
||||
case DynamicContentComponents.previous_stays:
|
||||
return null
|
||||
case DynamicContentComponents.upcoming_stays:
|
||||
return <UpcomingStays lang={lang} stays={user.stays} />
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default function Content({
|
||||
user,
|
||||
lang,
|
||||
content,
|
||||
}: {
|
||||
user: User
|
||||
lang: Lang
|
||||
content: AccountPageContentItem[]
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{content.map((item) => {
|
||||
switch (item.__typename) {
|
||||
case ContentEntries.AccountPageContentDynamicContent:
|
||||
return (
|
||||
<DynamicComponent
|
||||
user={user}
|
||||
lang={lang}
|
||||
content={item.dynamic_content}
|
||||
/>
|
||||
)
|
||||
case ContentEntries.AccountPageContentShortcuts:
|
||||
const shortcuts = item.shortcuts.shortcuts.map(
|
||||
(shortcut) => shortcut.linkConnection.edges[0].node
|
||||
)
|
||||
return (
|
||||
<Shortcuts
|
||||
shortcuts={shortcuts}
|
||||
subtitle={item.preamble}
|
||||
title={item.title}
|
||||
/>
|
||||
)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
})}
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user