refactor: make my-pages page more reusable

This commit is contained in:
Arvid Norlin
2024-04-30 14:48:20 +02:00
parent a1e474073e
commit a81f641ccd
9 changed files with 44 additions and 137 deletions

View File

@@ -1,9 +1,35 @@
import { redirect } from "next/navigation"
import { overview } from "@/constants/routes/myPages"
import { myPages, overview } from "@/constants/routes/myPages"
import { serverClient } from "@/lib/trpc/server"
import type { LangParams, PageArgs } from "@/types/params"
import MaxWidth from "@/components/MaxWidth"
import Content from "@/components/MyPages/AccountPage/Content"
export default function MyPages({ params }: PageArgs<LangParams>) {
redirect(overview[params.lang])
import styles from "./page.module.css"
import type { LangParams, PageArgs, UriParams } from "@/types/params"
export default async function MyPages({
params,
searchParams,
}: PageArgs<LangParams, UriParams>) {
if (!searchParams.uri) {
throw new Error("Bad URI")
}
const myPagesRoot = myPages[params.lang].replace(`/${params.lang}`, "")
if (searchParams.uri === myPagesRoot) {
redirect(overview[params.lang])
}
const accountPage = await serverClient().contentstack.accountPage.get({
url: searchParams.uri,
lang: params.lang,
})
return (
<MaxWidth className={styles.blocks} tag="main">
<Content lang={params.lang} content={accountPage.content} />
</MaxWidth>
)
}