diff --git a/app/employe/layout.tsx b/app/employe/layout.tsx index bf37252..dcc54b0 100644 --- a/app/employe/layout.tsx +++ b/app/employe/layout.tsx @@ -2,15 +2,33 @@ import { useAuth } from "@/contexts/AuthContext"; import { useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useEffect } from "react"; import { Loading } from "@/components/ui/Loading"; import toast from "react-hot-toast"; -import { Ticket, BarChart3, Menu, X } from "lucide-react"; -import Link from "next/link"; -import { usePathname } from "next/navigation"; -import Logo from "@/components/Logo"; +import { Ticket, BarChart3 } from "lucide-react"; +import { SharedSidebar, NavItem } from "@/components/shared/SharedSidebar"; import UserDropdown from "@/components/UserDropdown"; +const EMPLOYE_NAV_ITEMS: NavItem[] = [ + { + label: "Dashboard", + href: "/employe/dashboard", + icon: , + color: "green", + }, + { + label: "Validation des Tickets", + href: "/employe/verification", + icon: , + color: "emerald", + }, +]; + +const EMPLOYE_ACTIVE_STYLES: Record = { + green: "bg-gradient-to-r from-green-600 to-green-700 text-white shadow-lg shadow-green-500/30", + emerald: "bg-gradient-to-r from-emerald-600 to-teal-600 text-white shadow-lg shadow-emerald-500/30", +}; + export default function EmployeLayout({ children, }: { @@ -18,8 +36,6 @@ export default function EmployeLayout({ }) { const { user, isAuthenticated, isLoading, logout } = useAuth(); const router = useRouter(); - const pathname = usePathname(); - const [isOpen, setIsOpen] = useState(false); useEffect(() => { if (!isLoading && !isAuthenticated) { @@ -51,98 +67,14 @@ export default function EmployeLayout({ return null; } - const navItems = [ - { - label: "Dashboard", - href: "/employe/dashboard", - icon: , - color: "green", - }, - { - label: "Validation des Tickets", - href: "/employe/verification", - icon: , - color: "emerald", - }, - ]; - - const isActive = (href: string) => pathname === href; - - const getActiveStyles = (color: string) => { - const styles: Record = { - green: "bg-gradient-to-r from-green-600 to-green-700 text-white shadow-lg shadow-green-500/30", - emerald: "bg-gradient-to-r from-emerald-600 to-teal-600 text-white shadow-lg shadow-emerald-500/30", - }; - return styles[color] || styles.green; - }; - return (
- {/* Mobile menu button */} - - - {/* Overlay for mobile */} - {isOpen && ( -
setIsOpen(false)} - /> - )} - - {/* Sidebar */} - + {/* Main Content */}
diff --git a/components/admin/Sidebar.tsx b/components/admin/Sidebar.tsx index a3a288c..424bd0e 100644 --- a/components/admin/Sidebar.tsx +++ b/components/admin/Sidebar.tsx @@ -1,154 +1,70 @@ "use client"; -import Link from "next/link"; -import { usePathname } from "next/navigation"; import { LayoutDashboard, Users, Ticket, BarChart3, Gift, - Menu, - X, Trophy, } from "lucide-react"; -import { useState } from "react"; -import Logo from "@/components/Logo"; +import { SharedSidebar, NavItem } from "@/components/shared/SharedSidebar"; -interface NavItem { - label: string; - href: string; - icon: React.ReactNode; - color: string; -} +const ADMIN_NAV_ITEMS: NavItem[] = [ + { + label: "Dashboard", + href: "/admin/dashboard", + icon: , + color: "darkblue", + }, + { + label: "Utilisateurs", + href: "/admin/utilisateurs", + icon: , + color: "blue", + }, + { + label: "Tickets", + href: "/admin/tickets", + icon: , + color: "emerald", + }, + { + label: "Lots & Prix", + href: "/admin/lots", + icon: , + color: "purple", + }, + { + label: "Données Marketing", + href: "/admin/marketing-data", + icon: , + color: "indigo", + }, + { + label: "Tirages", + href: "/admin/tirages", + icon: , + color: "amber", + }, +]; + +const ADMIN_ACTIVE_STYLES: Record = { + darkblue: "bg-gradient-to-r from-[#1e3a5f] to-[#2d5a8f] text-white shadow-lg shadow-blue-900/30", + blue: "bg-gradient-to-r from-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-500/30", + emerald: "bg-gradient-to-r from-emerald-600 to-teal-600 text-white shadow-lg shadow-emerald-500/30", + purple: "bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg shadow-purple-500/30", + indigo: "bg-gradient-to-r from-indigo-600 to-purple-600 text-white shadow-lg shadow-indigo-500/30", + amber: "bg-gradient-to-r from-amber-500 to-orange-600 text-white shadow-lg shadow-amber-500/30", +}; export default function Sidebar() { - const pathname = usePathname(); - const [isOpen, setIsOpen] = useState(false); - - const navItems: NavItem[] = [ - { - label: "Dashboard", - href: "/admin/dashboard", - icon: , - color: "darkblue", - }, - { - label: "Utilisateurs", - href: "/admin/utilisateurs", - icon: , - color: "blue", - }, - { - label: "Tickets", - href: "/admin/tickets", - icon: , - color: "emerald", - }, - { - label: "Lots & Prix", - href: "/admin/lots", - icon: , - color: "purple", - }, - { - label: "Données Marketing", - href: "/admin/marketing-data", - icon: , - color: "indigo", - }, - { - label: "Tirages", - href: "/admin/tirages", - icon: , - color: "amber", - }, - ]; - - const isActive = (href: string) => { - return pathname === href; - }; - - const getActiveStyles = (color: string) => { - const styles: Record = { - darkblue: "bg-gradient-to-r from-[#1e3a5f] to-[#2d5a8f] text-white shadow-lg shadow-blue-900/30", - blue: "bg-gradient-to-r from-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-500/30", - emerald: "bg-gradient-to-r from-emerald-600 to-teal-600 text-white shadow-lg shadow-emerald-500/30", - purple: "bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg shadow-purple-500/30", - indigo: "bg-gradient-to-r from-indigo-600 to-purple-600 text-white shadow-lg shadow-indigo-500/30", - amber: "bg-gradient-to-r from-amber-500 to-orange-600 text-white shadow-lg shadow-amber-500/30", - }; - return styles[color] || styles.blue; - }; - return ( - <> - {/* Mobile menu button */} - - - {/* Overlay for mobile */} - {isOpen && ( -
setIsOpen(false)} - /> - )} - - {/* Sidebar */} - - + ); } diff --git a/components/shared/SharedSidebar.tsx b/components/shared/SharedSidebar.tsx new file mode 100644 index 0000000..7acf3b7 --- /dev/null +++ b/components/shared/SharedSidebar.tsx @@ -0,0 +1,102 @@ +"use client"; + +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { Menu, X } from "lucide-react"; +import { useState } from "react"; +import Logo from "@/components/Logo"; + +export interface NavItem { + label: string; + href: string; + icon: React.ReactNode; + color: string; +} + +export interface SidebarProps { + navItems: NavItem[]; + title: string; + subtitle: string; + activeStyles: Record; +} + +export function SharedSidebar({ navItems, title, subtitle, activeStyles }: SidebarProps) { + const pathname = usePathname(); + const [isOpen, setIsOpen] = useState(false); + + const isActive = (href: string) => pathname === href; + + const getActiveStyles = (color: string) => { + return activeStyles[color] || activeStyles[Object.keys(activeStyles)[0]]; + }; + + return ( + <> + {/* Mobile menu button */} + + + {/* Overlay for mobile */} + {isOpen && ( +
setIsOpen(false)} + /> + )} + + {/* Sidebar */} + + + ); +}