Remove invalid comparisons against lowercase 'employee' role that don't exist in the User type. The role type only includes uppercase 'EMPLOYEE'. Fixed in: - app/employe/dashboard/page.tsx (lines 42, 117) - app/employe/layout.tsx (lines 28, 48) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
134 lines
3.9 KiB
TypeScript
134 lines
3.9 KiB
TypeScript
"use client";
|
|
|
|
import { useAuth } from "@/contexts/AuthContext";
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect } from "react";
|
|
import { Loading } from "@/components/ui/Loading";
|
|
import toast from "react-hot-toast";
|
|
import { LogOut, Ticket, BarChart3 } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
import Logo from "@/components/Logo";
|
|
|
|
export default function EmployeLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const { user, isAuthenticated, isLoading, logout } = useAuth();
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
if (!isLoading && !isAuthenticated) {
|
|
router.push("/login");
|
|
return;
|
|
}
|
|
|
|
if (isAuthenticated && user?.role !== "EMPLOYEE") {
|
|
router.push("/");
|
|
toast.error("Accès refusé : rôle employé requis");
|
|
return;
|
|
}
|
|
}, [isLoading, isAuthenticated, user, router]);
|
|
|
|
const handleLogout = async () => {
|
|
await logout();
|
|
router.push("/login");
|
|
};
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
<Loading size="lg" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isAuthenticated || user?.role !== "EMPLOYEE") {
|
|
return null;
|
|
}
|
|
|
|
const navItems = [
|
|
{
|
|
label: "Validation des Tickets",
|
|
href: "/employe/verification",
|
|
icon: <Ticket className="w-5 h-5" />,
|
|
},
|
|
{
|
|
label: "Dashboard",
|
|
href: "/employe/dashboard",
|
|
icon: <BarChart3 className="w-5 h-5" />,
|
|
},
|
|
];
|
|
|
|
const isActive = (href: string) => pathname === href;
|
|
|
|
return (
|
|
<div className="flex min-h-screen bg-gray-50">
|
|
{/* Sidebar */}
|
|
<aside className="w-64 bg-white shadow-lg border-r border-gray-200 flex flex-col">
|
|
{/* Logo/Header */}
|
|
<div className="p-6 border-b border-gray-200">
|
|
<h2 className="text-xl font-bold text-gray-900">Thé Tip Top</h2>
|
|
<p className="text-sm text-gray-500 mt-1">Espace Employé</p>
|
|
</div>
|
|
|
|
{/* Navigation */}
|
|
<nav className="flex-1 p-4 space-y-2">
|
|
{navItems.map((item) => (
|
|
<Link
|
|
key={item.href}
|
|
href={item.href}
|
|
className={`
|
|
flex items-center gap-3 px-4 py-3 rounded-lg transition-colors
|
|
${
|
|
isActive(item.href)
|
|
? "bg-green-600 text-white"
|
|
: "text-gray-700 hover:bg-gray-100"
|
|
}
|
|
`}
|
|
>
|
|
{item.icon}
|
|
<span className="font-medium">{item.label}</span>
|
|
</Link>
|
|
))}
|
|
</nav>
|
|
</aside>
|
|
|
|
{/* Main Content */}
|
|
<div className="flex-1 flex flex-col">
|
|
{/* Header */}
|
|
<header className="bg-white shadow-sm border-b border-gray-200 px-6 py-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-4">
|
|
<Logo size="md" showText={false} />
|
|
<div>
|
|
<h1 className="text-2xl font-bold text-gray-900">
|
|
Thé Tip Top - Espace Employé
|
|
</h1>
|
|
<p className="text-sm text-gray-500 mt-1">
|
|
Connecté en tant que{" "}
|
|
<span className="font-medium">
|
|
{user?.firstName} {user?.lastName}
|
|
</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<button
|
|
onClick={handleLogout}
|
|
className="flex items-center gap-2 px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors"
|
|
>
|
|
<LogOut className="w-4 h-4" />
|
|
Déconnexion
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
{/* Page Content */}
|
|
<main className="flex-1 overflow-auto">{children}</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|