Files
frontend/src/app/(user)/layout.tsx

59 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-01-11 21:30:57 +05:30
'use client';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { Footer } from '@/components/layout/Footer';
import { CommonHeader } from '@/components/layout/CommonHeader';
2026-01-11 21:30:57 +05:30
2026-01-11 21:21:34 +05:30
export default function UserLayout({
children,
}: {
children: React.ReactNode;
}) {
2026-01-11 21:30:57 +05:30
const { data: session, status } = useSession();
const router = useRouter();
useEffect(() => {
if (status === 'loading') return;
if (!session) {
router.replace('/login');
return;
}
// Redirect agents to agent dashboard
const userRole = (session.user as any)?.role;
if (userRole === 'AGENT') {
router.replace('/agent/dashboard');
}
}, [session, status, router]);
if (status === 'loading' || !session) {
return (
<div className="min-h-screen bg-white flex items-center justify-center">
2026-01-11 21:30:57 +05:30
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[#00293d]"></div>
</div>
);
}
return (
<div className="min-h-screen bg-[#f0f4f3] flex flex-col">
2026-01-11 21:30:57 +05:30
{/* Header */}
<div className="sticky top-0 z-50 px-4 py-3 bg-[#f0f4f3]">
<div className="max-w-7xl mx-auto">
<CommonHeader />
</div>
</div>
2026-01-11 21:30:57 +05:30
{/* Main Content */}
<main className="flex-1">
{children}
</main>
2026-01-11 21:30:57 +05:30
{/* Footer */}
<Footer />
2026-01-11 21:30:57 +05:30
</div>
);
2026-01-11 21:21:34 +05:30
}