import React, { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate, Outlet } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import { useWebsites } from '../context/WebsiteContext'; import toast from 'react-hot-toast'; import { LayoutDashboard, MessageSquare, FileText, HelpCircle, Settings as SettingsIcon, LogOut, Menu, X, User, Globe, Users, Bell } from 'lucide-react'; const Layout = ({ children }) => { const { user, logout } = useAuth(); const { websites } = useWebsites(); const location = useLocation(); const navigate = useNavigate(); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [unreadNotifications, setUnreadNotifications] = useState(0); const hasWebsites = websites.length > 0; useEffect(() => { const fetchUnreadCount = async () => { try { const response = await api.get('/notifications/unread-count'); setUnreadNotifications(response.data.count); } catch (error) { console.error('Failed to fetch unread count:', error); } }; if (user) { fetchUnreadCount(); const interval = setInterval(fetchUnreadCount, 60000); // Poll every minute return () => clearInterval(interval); } }, [user]); const handleLogout = () => { logout(); navigate('/login'); }; const navItems = [ { icon: LayoutDashboard, label: 'Dashboard', path: '/dashboard' }, { icon: Globe, label: 'Websites', path: '/websites' }, { icon: MessageSquare, label: 'Chats', path: '/chats' }, { icon: Users, label: 'Users', path: '/users' }, { icon: FileText, label: 'Content', path: '/content' }, { icon: HelpCircle, label: 'Unanswered', path: '/unanswered-questions' }, { icon: MessageSquare, label: 'FAQs', path: '/faqs' }, { icon: Bell, label: 'Notifications', path: '/notifications' }, { icon: SettingsIcon, label: 'Settings', path: '/settings' }, ]; return (
{/* Sidebar */} {/* Mobile Overlay */} {isSidebarOpen && (
setIsSidebarOpen(false)} /> )} {/* Main Content */}
CustomerAgent
{unreadNotifications > 0 && ( )}
{/* Page Content */}
); }; export default Layout;