40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
import { useEffect } from 'react';
|
|
import { useRouter } from 'next/navigation';
|
|
import { useAuth } from '@/lib/auth-context';
|
|
import Sidebar from '@/components/layout/Sidebar';
|
|
|
|
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
|
const { user, loading } = useAuth();
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (!loading) {
|
|
if (!user) {
|
|
router.push('/login');
|
|
} else if (user.role !== 'hr_admin' && user.role !== 'super_admin') {
|
|
router.push('/dashboard');
|
|
}
|
|
}
|
|
}, [user, loading, router]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex items-center justify-center min-h-screen bg-[#F8FAFC]">
|
|
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600"></div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!user || (user.role !== 'hr_admin' && user.role !== 'super_admin')) return null;
|
|
|
|
return (
|
|
<div className="flex min-h-screen bg-[#F8FAFC]">
|
|
<Sidebar />
|
|
<main className="flex-1 overflow-auto">{children}</main>
|
|
</div>
|
|
);
|
|
}
|