import { useState, useEffect, useRef } from 'react' import { Outlet, Link, useLocation, useNavigate } from 'react-router-dom' import { useAuth } from '../contexts/AuthContext' import { notificationApi } from '../api/client' import { LayoutDashboard, Ticket, Users, Settings, LogOut, Plus, Cog, Bell, Check, Trash2 } from 'lucide-react' const navigation = [ { name: 'Панель', href: '/', icon: LayoutDashboard }, { name: 'Заявки', href: '/tickets', icon: Ticket }, { name: 'Пользователи', href: '/users', icon: Users }, { name: 'Справочники', href: '/reference', icon: Settings }, { name: 'Шаблоны', href: '/templates', icon: Bell }, { name: 'Настройки', href: '/settings', icon: Cog }, ] export default function Layout() { const { user, logout } = useAuth() const location = useLocation() const navigate = useNavigate() const [notifications, setNotifications] = useState([]) const [unreadCount, setUnreadCount] = useState(0) const [showDropdown, setShowDropdown] = useState(false) const dropdownRef = useRef(null) const loadNotifications = () => { notificationApi.getNotifications().then(res => { setNotifications(res.data.notifications) setUnreadCount(res.data.unread_count) }).catch(() => {}) } useEffect(() => { loadNotifications() const interval = setInterval(loadNotifications, 30000) return () => clearInterval(interval) }, []) useEffect(() => { const handleClick = (e: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) { setShowDropdown(false) } } document.addEventListener('mousedown', handleClick) return () => document.removeEventListener('mousedown', handleClick) }, []) const handleMarkRead = async (id: number) => { await notificationApi.markAsRead(id) loadNotifications() } const handleMarkAllRead = async () => { await notificationApi.markAllAsRead() loadNotifications() } const handleDelete = async (id: number) => { await notificationApi.deleteNotification(id) loadNotifications() } const handleLogout = () => { logout() navigate('/login') } return (
{/* Sidebar */}

Сервис Деск

Система обработки заявок

{user?.first_name?.[0]}{user?.last_name?.[0]}

{user?.first_name} {user?.last_name}

{user?.email}

{/* Main content */}
{/* Header */}

{navigation.find(n => n.href === location.pathname || (n.href !== '/' && location.pathname.startsWith(n.href)))?.name || 'Панель'}

{/* Notification bell */}
{showDropdown && (
Уведомления {unreadCount > 0 && ( )}
{notifications.length === 0 ? (

Нет уведомлений

) : ( notifications.map(n => (

{n.title}

{n.message}

{n.created_at ? new Date(n.created_at).toLocaleString('ru-RU') : ''}

{n.is_read === 0 && ( )}
)) )}
)}
Новая заявка
) }