Spaces:
Running
Running
File size: 8,221 Bytes
d96d2a2 d3ec6da d96d2a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | import React from 'react';
import { NavLink, useNavigate } from 'react-router-dom';
import {
LayoutDashboard,
Inbox,
Users,
BarChart3,
UserCircle,
Settings,
LogOut,
Activity,
ChevronLeft,
ChevronRight
} from 'lucide-react';
import useAuthStore from '../../store/authStore';
const AdminSidebar = ({ isMobile, onClose, isCollapsed, onToggleCollapse }) => {
const navItems = [
{ label: 'Dashboard', path: '/admin/dashboard', icon: LayoutDashboard },
{ label: 'Tickets', path: '/admin/tickets', icon: Inbox },
{ label: 'Users', path: '/admin/users', icon: Users },
{ label: 'Analytics', path: '/admin/analytics', icon: BarChart3 },
{ label: 'Profile', path: '/admin/profile', icon: UserCircle },
];
const { logout } = useAuthStore();
const navigate = useNavigate();
const handleLogout = async () => {
await logout();
navigate('/login');
};
const showLabels = isMobile || !isCollapsed;
return (
<aside
className={`${isMobile ? 'w-full h-full' : 'fixed left-0 top-0 h-full'} z-40 transition-all duration-300 overflow-hidden flex flex-col`}
style={{
width: isMobile ? '100%' : (isCollapsed ? '80px' : '260px'),
background: '#ffffff',
borderRight: '1px solid #f0fdf4',
boxShadow: '2px 0 12px rgba(0,0,0,0.04)'
}}
>
{/* Logo Section */}
<div className="p-6 border-b border-gray-50 flex items-center" style={{ justifyContent: showLabels ? 'space-between' : 'center', padding: isCollapsed && !isMobile ? '24px 16px' : '24px 32px' }}>
<div className="flex items-center gap-3">
<img
src="/favicon.png"
alt="HelpDesk.ai Logo"
style={{
height: showLabels ? '32px' : '32px',
width: showLabels ? 'auto' : '32px',
objectFit: 'contain',
borderRadius: showLabels ? '0' : '8px'
}}
/>
{showLabels && (
<div className="animate-in fade-in duration-500 flex flex-col justify-center">
<p className="text-[10px] text-gray-500 font-bold uppercase tracking-[0.2em]">Admin Console</p>
</div>
)}
</div>
{!isMobile && onToggleCollapse && (
<button
onClick={onToggleCollapse}
style={{
background: '#f0fdf4', border: '1px solid #d1fae5',
borderRadius: '8px', padding: '4px', cursor: 'pointer',
color: '#15803d', display: 'flex', alignItems: 'center',
justifyContent: 'center', transition: 'all 0.2s ease',
position: isCollapsed ? 'absolute' : 'relative',
right: isCollapsed ? '-12px' : 'auto',
top: isCollapsed ? '28px' : 'auto',
zIndex: 50, boxShadow: '0 1px 4px rgba(0,0,0,0.08)'
}}
className="hover:bg-emerald-100"
>
{isCollapsed ? <ChevronRight size={16} /> : <ChevronLeft size={16} />}
</button>
)}
</div>
{/* Navigation Links */}
<nav className="flex-1 px-3 py-8 space-y-1.5 overflow-y-auto custom-scrollbar">
{showLabels && (
<p style={{ fontSize: '10px', letterSpacing: '0.14em', color: '#9ca3af', fontWeight: 600, paddingLeft: '14px', marginBottom: '16px' }} className="uppercase">
CORE MODULES
</p>
)}
{navItems.map((item) => (
<NavLink
key={item.path}
to={item.path}
onClick={isMobile ? onClose : undefined}
style={({ isActive }) => ({
display: 'flex', alignItems: 'center', gap: '12px',
borderRadius: '10px', padding: isCollapsed && !isMobile ? '10px' : '9px 14px',
color: isActive ? '#15803d' : '#6b7280',
background: isActive ? '#f0fdf4' : 'transparent',
fontWeight: isActive ? 600 : 500,
textDecoration: 'none', transition: 'all 0.2s ease',
justifyContent: isCollapsed && !isMobile ? 'center' : 'flex-start'
})}
className="group hover:bg-gray-50 relative"
>
<item.icon size={20} className="shrink-0 transition-transform group-hover:scale-110" />
{showLabels && (
<span className="text-sm tracking-tight truncate animate-in fade-in slide-in-from-left-2 duration-300">
{item.label}
</span>
)}
{/* Tooltip for collapsed mode */}
{isCollapsed && !isMobile && (
<div className="absolute left-full ml-3 bg-gray-900 text-white text-xs py-1.5 px-3 rounded-lg opacity-0 group-hover:opacity-100 pointer-events-none transition-opacity z-50 whitespace-nowrap shadow-lg" style={{ top: '50%', transform: 'translateY(-50%)' }}>
{item.label}
</div>
)}
</NavLink>
))}
</nav>
{/* Bottom Profile / Logout Shortcut */}
<div className="p-4 border-t border-gray-50 space-y-1.5 pb-8 flex flex-col items-stretch">
<NavLink
to="/admin/settings"
onClick={isMobile ? onClose : undefined}
style={({ isActive }) => ({
display: 'flex', alignItems: 'center', gap: '12px',
borderRadius: '10px', padding: isCollapsed && !isMobile ? '10px' : '9px 14px',
color: isActive ? '#15803d' : '#6b7280',
background: isActive ? '#f0fdf4' : 'transparent',
fontWeight: isActive ? 600 : 500,
textDecoration: 'none', transition: 'all 0.2s ease',
justifyContent: isCollapsed && !isMobile ? 'center' : 'flex-start'
})}
className="group hover:bg-gray-50"
>
<Settings size={20} className="shrink-0 group-hover:rotate-45 transition-transform duration-300" />
{showLabels && <span className="text-sm tracking-tight animate-in fade-in duration-300">Settings</span>}
</NavLink>
<button
onClick={handleLogout}
style={{
display: 'flex', alignItems: 'center', gap: '12px',
borderRadius: '10px', padding: isCollapsed && !isMobile ? '10px' : '9px 14px',
color: '#6b7280', background: 'transparent',
fontWeight: 500, border: 'none', cursor: 'pointer',
transition: 'all 0.2s ease', width: '100%',
justifyContent: isCollapsed && !isMobile ? 'center' : 'flex-start'
}}
className="group hover:bg-red-50 hover:text-red-600"
>
<LogOut size={20} className="shrink-0 group-hover:translate-x-1 transition-transform" />
{showLabels && <span className="text-sm tracking-tight animate-in fade-in duration-300">Logout</span>}
</button>
</div>
</aside>
);
};
export default AdminSidebar;
|