podzahr/components/AdminLayout.tsx
nfel 91c149e92e
main: vibe coded app to feel like paper
Signed-off-by: nfel <nfilsaraee@gmail.com>
2025-12-30 00:00:16 +03:30

36 lines
881 B
TypeScript

'use client';
import { useEffect } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { useAdmin } from '@/lib/AdminContext';
import AdminSidebar from './AdminSidebar';
export default function AdminLayout({ children }: { children: React.ReactNode }) {
const { isAuthenticated } = useAdmin();
const router = useRouter();
const pathname = usePathname();
useEffect(() => {
if (!isAuthenticated && pathname !== '/admin') {
router.push('/admin');
}
}, [isAuthenticated, router, pathname]);
if (!isAuthenticated && pathname !== '/admin') {
return null;
}
if (pathname === '/admin') {
return <>{children}</>;
}
return (
<div className="min-h-screen bg-paper-light flex">
<AdminSidebar />
<main className="flex-1 overflow-auto bg-paper-sand/30">
{children}
</main>
</div>
);
}