'use client'; import React, { useEffect, useState } from 'react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import './sidebar.scss'; import Cookies from 'js-cookie'; interface AdminUser { name: string; role: string; email: string; } const Sidebar = () => { const pathname = usePathname(); const router = useRouter(); const [adminUser, setAdminUser] = useState(null); useEffect(() => { const userJson = localStorage.getItem('adminUser'); if (userJson) { try { const user = JSON.parse(userJson); setAdminUser(user); } catch (error) { console.error('Failed to parse admin user', error); } } }, []); const handleLogout = async () => { try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/admin/logout`, { method: 'POST', credentials: 'include', }); localStorage.removeItem('adminToken'); localStorage.removeItem('adminUser'); Cookies.remove('adminTokenSync', { path: '/' }); router.push('/admin/login'); } catch (error) { console.error('Logout failed:', error); } }; const navigation = [ { section: 'Dashboard', items: [ { path: '/admin/dashboard', label: 'Overview', icon: '📊' } ] }, { section: 'Products', items: [ { path: '/admin/products', label: 'Products', icon: '📦' } ] }, { section: 'Categories', items: [ { path: '/admin/categories', label: 'Categories', icon: '🗂️' } ] }, { section: 'Careers', items: [ { path: '/admin/careers', label: 'Job Listings', icon: '💼' }, { path: '/admin/careers/applications', label: 'Applications', icon: '📝' } ] }, { section: 'Sales', items: [ { path: '/admin/orders', label: 'Orders', icon: '🛍️' }, { path: '/admin/orders/tracking', label: 'Order Tracking', icon: '🚚' }, { path: '/admin/customers', label: 'Customers', icon: '👥' } ] }, { section: 'Settings', items: [ { path: '/admin/payment-methods', label: 'Payment Methods', icon: '💳' }, { path: '/admin/users', label: 'Users', icon: '👤' }, { path: '/admin/settings', label: 'General Settings', icon: '⚙️' } ] } ]; return (

Admin Panel

{adminUser && (
{adminUser.name ? adminUser.name.charAt(0).toUpperCase() : 'A'}

{adminUser.name || 'Admin User'}

{adminUser.role || 'administrator'}

)}
); }; export default Sidebar;