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 { ProjectView } from "@/components/views/admin/project";
|
||||
import { PostView } from "@/components/views/admin/post";
|
||||
import { redirect } from 'next/navigation'
|
||||
import { redirect } from "next/navigation";
|
||||
import { ReactNode } from "react";
|
||||
import { IOptionalChildrenProps, ISlugArrayProps } from "@/components/shared/props";
|
||||
import {
|
||||
IOptionalChildrenProps,
|
||||
ISlugArrayProps,
|
||||
} from "@/components/shared/props";
|
||||
|
||||
const viewMapRecords: Record<string, ReactNode> = {
|
||||
"home": <div>home</div>,
|
||||
"man-post": <PostView/>,
|
||||
"man-proj": <ProjectView/>
|
||||
}
|
||||
home: <div>home</div>,
|
||||
"man-post": <PostView />,
|
||||
"man-proj": <ProjectView />,
|
||||
};
|
||||
|
||||
const sidebarEntries: SidebarEntry[] = [
|
||||
{ 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" },
|
||||
];
|
||||
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
|
||||
|
||||
function getCurrentView(view: string): ReactNode {
|
||||
const viewJSX = viewMapRecords[view || "home"];
|
||||
return viewJSX;
|
||||
}
|
||||
|
||||
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
|
||||
|
||||
export default async function Page({ params: { slug = ["home"] } }: AdminPageProps) {
|
||||
if (
|
||||
(await sidebarEntries)
|
||||
.map((entry) => entry.view)
|
||||
.indexOf(slug.toString()) < 0
|
||||
) redirect("/admin/")
|
||||
export default async function Page({
|
||||
params: { slug = ["home"] },
|
||||
}: AdminPageProps) {
|
||||
const sidebarEntries: SidebarEntry[] = [
|
||||
{ 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" },
|
||||
];
|
||||
if (sidebarEntries.map((entry) => entry.view).indexOf(slug.toString()) < 0)
|
||||
redirect("/admin/");
|
||||
return (
|
||||
<main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0">
|
||||
<AuthHandler params={null}>
|
||||
<Sidebar
|
||||
sidebarEntries={sidebarEntries}
|
||||
params={{slug: slug.toString()}}
|
||||
params={{ slug: slug.toString() }}
|
||||
/>
|
||||
<div className="AdminPanelWrapper flex flex-col p-2">
|
||||
{getCurrentView(slug.toString())}
|
||||
{viewMapRecords[slug.toString() || "home"]}
|
||||
</div>
|
||||
</AuthHandler>
|
||||
{/* <section>{JSON.stringify(cookies().getAll())}</section> */}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user