refactor: make my-pages page more reusable
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user