52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useEffect } from "react";
|
|
import { useAuth } from "../../frontend/components/AuthProvider";
|
|
import {
|
|
getConfigRedirect,
|
|
getConfigTabs,
|
|
} from "../../frontend/utils/config-access";
|
|
|
|
export default function ConfigLayout({ children }: { children: React.ReactNode }) {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { status, isAdmin } = useAuth();
|
|
const tabs = getConfigTabs(isAdmin);
|
|
const redirectTarget = getConfigRedirect(pathname, isAdmin);
|
|
|
|
useEffect(() => {
|
|
if (status !== "signed-in") return;
|
|
if (redirectTarget) router.replace(redirectTarget);
|
|
}, [status, redirectTarget, router]);
|
|
|
|
if (
|
|
status !== "signed-in" ||
|
|
redirectTarget !== null
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className="container-fluid py-4">
|
|
<div className="page-header">
|
|
<h1>Config</h1>
|
|
</div>
|
|
|
|
<nav className="config-tabs">
|
|
{tabs.map((tab) => (
|
|
<Link
|
|
key={tab.href}
|
|
href={tab.href}
|
|
className={pathname?.startsWith(tab.href) ? "config-tab active" : "config-tab"}
|
|
>
|
|
{tab.label}
|
|
</Link>
|
|
))}
|
|
</nav>
|
|
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|