refactor of the admin panel page
This commit is contained in:
parent
2c3ccfee18
commit
dc66da7d00
@ -4,46 +4,42 @@ import AuthHandler from "@/components/server/admin/authHandler";
|
|||||||
import Sidebar, { SidebarEntry } from "@/components/server/admin/views/sidebar";
|
import Sidebar, { SidebarEntry } from "@/components/server/admin/views/sidebar";
|
||||||
import { ProjectView } from "@/components/views/admin/project";
|
import { ProjectView } from "@/components/views/admin/project";
|
||||||
import { PostView } from "@/components/views/admin/post";
|
import { PostView } from "@/components/views/admin/post";
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from "next/navigation";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { IOptionalChildrenProps, ISlugArrayProps } from "@/components/shared/props";
|
import {
|
||||||
|
IOptionalChildrenProps,
|
||||||
|
ISlugArrayProps,
|
||||||
|
} from "@/components/shared/props";
|
||||||
|
|
||||||
const viewMapRecords: Record<string, ReactNode> = {
|
const viewMapRecords: Record<string, ReactNode> = {
|
||||||
"home": <div>home</div>,
|
home: <div>home</div>,
|
||||||
"man-post": <PostView/>,
|
"man-post": <PostView />,
|
||||||
"man-proj": <ProjectView/>
|
"man-proj": <ProjectView />,
|
||||||
}
|
};
|
||||||
|
|
||||||
const sidebarEntries: SidebarEntry[] = [
|
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
|
||||||
{ label: "Home", view: "home" },
|
|
||||||
{ label: "Post Management", view: "man-post" },
|
|
||||||
{ label: "Project Management", view: "man-proj" },
|
|
||||||
{ label: "Tag Management", view: "man-tags" },
|
|
||||||
{ label: "User Management", view: "man-user" },
|
|
||||||
];
|
|
||||||
|
|
||||||
function getCurrentView(view: string): ReactNode {
|
export default async function Page({
|
||||||
const viewJSX = viewMapRecords[view || "home"];
|
params: { slug = ["home"] },
|
||||||
return viewJSX;
|
}: AdminPageProps) {
|
||||||
}
|
const sidebarEntries: SidebarEntry[] = [
|
||||||
|
{ label: "Home", view: "home" },
|
||||||
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
|
{ label: "Post Management", view: "man-post" },
|
||||||
|
{ label: "Project Management", view: "man-proj" },
|
||||||
export default async function Page({ params: { slug = ["home"] } }: AdminPageProps) {
|
{ label: "Tag Management", view: "man-tags" },
|
||||||
if (
|
{ label: "User Management", view: "man-user" },
|
||||||
(await sidebarEntries)
|
];
|
||||||
.map((entry) => entry.view)
|
if (sidebarEntries.map((entry) => entry.view).indexOf(slug.toString()) < 0)
|
||||||
.indexOf(slug.toString()) < 0
|
redirect("/admin/");
|
||||||
) redirect("/admin/")
|
|
||||||
return (
|
return (
|
||||||
<main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0">
|
<main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0">
|
||||||
<AuthHandler params={null}>
|
<AuthHandler params={null}>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
sidebarEntries={sidebarEntries}
|
sidebarEntries={sidebarEntries}
|
||||||
params={{slug: slug.toString()}}
|
params={{ slug: slug.toString() }}
|
||||||
/>
|
/>
|
||||||
<div className="AdminPanelWrapper flex flex-col p-2">
|
<div className="AdminPanelWrapper flex flex-col p-2">
|
||||||
{getCurrentView(slug.toString())}
|
{viewMapRecords[slug.toString() || "home"]}
|
||||||
</div>
|
</div>
|
||||||
</AuthHandler>
|
</AuthHandler>
|
||||||
{/* <section>{JSON.stringify(cookies().getAll())}</section> */}
|
{/* <section>{JSON.stringify(cookies().getAll())}</section> */}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user