fix: move user fetch

This commit is contained in:
Arvid Norlin
2024-04-25 14:35:48 +02:00
parent 840a20c4c1
commit 2ddcbff009
6 changed files with 12 additions and 14 deletions

View File

@@ -7,7 +7,6 @@ import styles from "./page.module.css"
import type { LangParams, PageArgs } from "@/types/params" import type { LangParams, PageArgs } from "@/types/params"
export default async function BenefitsPage({ params }: PageArgs<LangParams>) { export default async function BenefitsPage({ params }: PageArgs<LangParams>) {
const user = await serverClient().user.get()
const accountPage = await serverClient().contentstack.accountPage.getBenefits( const accountPage = await serverClient().contentstack.accountPage.getBenefits(
{ {
lang: params.lang, lang: params.lang,
@@ -16,7 +15,7 @@ export default async function BenefitsPage({ params }: PageArgs<LangParams>) {
return ( return (
<main className={styles.container}> <main className={styles.container}>
<Content user={user} lang={params.lang} content={accountPage.content} /> <Content lang={params.lang} content={accountPage.content} />
</main> </main>
) )
} }

View File

@@ -1,15 +1,14 @@
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import { serverClient } from "@/lib/trpc/server" import { serverClient } from "@/lib/trpc/server"
import Content from "@/components/MyPages/AccountPage/Content"
import MaxWidth from "@/components/MaxWidth" import MaxWidth from "@/components/MaxWidth"
import Content from "@/components/MyPages/AccountPage/Content"
import styles from "./page.module.css" import styles from "./page.module.css"
import type { LangParams, PageArgs } from "@/types/params" import type { LangParams, PageArgs } from "@/types/params"
export default async function MyPageOverview({ params }: PageArgs<LangParams>) { export default async function MyPageOverview({ params }: PageArgs<LangParams>) {
const user = await serverClient().user.get()
const accountPage = await serverClient().contentstack.accountPage.getOverview( const accountPage = await serverClient().contentstack.accountPage.getOverview(
{ {
lang: params.lang, lang: params.lang,
@@ -18,7 +17,7 @@ export default async function MyPageOverview({ params }: PageArgs<LangParams>) {
return ( return (
<MaxWidth className={styles.blocks} tag="main"> <MaxWidth className={styles.blocks} tag="main">
<Content user={user} lang={params.lang} content={accountPage.content} /> <Content lang={params.lang} content={accountPage.content} />
</MaxWidth> </MaxWidth>
) )
} }

View File

@@ -18,10 +18,10 @@ import {
DynamicContentComponents, DynamicContentComponents,
} from "@/types/requests/myPages/accountpage" } from "@/types/requests/myPages/accountpage"
function DynamicComponent({ user, component, props }: AccountPageContentProps) { function DynamicComponent({ component, props }: AccountPageContentProps) {
switch (component) { switch (component) {
case DynamicContentComponents.membership_overview: case DynamicContentComponents.membership_overview:
return <Overview user={user} title={props.title} /> return <Overview title={props.title} />
case DynamicContentComponents.previous_stays: case DynamicContentComponents.previous_stays:
return <PreviousStays {...props} /> return <PreviousStays {...props} />
case DynamicContentComponents.soonest_stays: case DynamicContentComponents.soonest_stays:
@@ -37,7 +37,7 @@ function DynamicComponent({ user, component, props }: AccountPageContentProps) {
} }
} }
export default function Content({ user, lang, content }: ContentProps) { export default function Content({ lang, content }: ContentProps) {
return ( return (
<> <>
{content.map((item) => { {content.map((item) => {
@@ -61,7 +61,6 @@ export default function Content({ user, lang, content }: ContentProps) {
return ( return (
<DynamicComponent <DynamicComponent
component={item.dynamic_content.component} component={item.dynamic_content.component}
user={user}
props={componentProps} props={componentProps}
/> />
) )

View File

@@ -1,3 +1,5 @@
import { serverClient } from "@/lib/trpc/server"
import Title from "@/components/Title" import Title from "@/components/Title"
import Friend from "./Friend" import Friend from "./Friend"
@@ -7,7 +9,9 @@ import styles from "./overview.module.css"
import type { OverviewProps } from "@/types/components/myPages/myPage/overview" import type { OverviewProps } from "@/types/components/myPages/myPage/overview"
export default function Overview({ user, title }: OverviewProps) { export default async function Overview({ title }: OverviewProps) {
const user = await serverClient().user.get()
return ( return (
<section className={styles.container}> <section className={styles.container}>
<header> <header>

View File

@@ -1,9 +1,9 @@
import { Lang } from "@/constants/languages" import { Lang } from "@/constants/languages"
import { import {
AccountPageContentItem, AccountPageContentItem,
DynamicContentComponents, DynamicContentComponents,
} from "@/types/requests/myPages/accountpage" } from "@/types/requests/myPages/accountpage"
import { User } from "@/types/user"
export type AccountPageContentProps = { export type AccountPageContentProps = {
component: DynamicContentComponents component: DynamicContentComponents
@@ -13,7 +13,6 @@ export type AccountPageContentProps = {
link?: { href: string; text: string } link?: { href: string; text: string }
lang: Lang lang: Lang
} }
user: User
} }
export type AccountPageComponentProps = { export type AccountPageComponentProps = {
@@ -24,7 +23,6 @@ export type AccountPageComponentProps = {
} }
export type ContentProps = { export type ContentProps = {
user: User
lang: Lang lang: Lang
content: AccountPageContentItem[] content: AccountPageContentItem[]
} }

View File

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