import React from 'react'; import { useQuery } from '@apollo/client'; import { useIsClient } from '@/lib/useIsomorphicLayoutEffect'; import { GET_CLIENT_ME } from '@/lib/graphql'; interface ProfileSidebarProps { activeItem: string; } const ProfileSidebar: React.FC = ({ activeItem }) => { const isClient = useIsClient(); // Получаем данные клиента для проверки наличия юридических лиц const { data: clientData } = useQuery(GET_CLIENT_ME, { skip: !isClient, errorPolicy: 'ignore' // Игнорируем ошибки, чтобы не ломать интерфейс }); // Проверяем есть ли у клиента юридические лица const hasLegalEntities = clientData?.clientMe?.legalEntities && clientData.clientMe.legalEntities.length > 0; const menuItems = [ { id: 'orders', icon: 'order', label: 'Заказы', href: '/profile-orders' }, { id: 'history', icon: 'history', label: 'История поиска', href: '/profile-history' }, { id: 'notifications', icon: 'bell', label: 'Уведомления', href: '/profile-notifications' }, { id: 'messages', icon: 'message', label: 'Оповещения', href: '/profile-messages' }, { id: 'addresses', icon: 'location', label: 'Адреса доставки', href: '/profile-addresses' }, { id: 'garage', icon: 'garage', label: 'Гараж', href: '/profile-garage' }, { id: 'settings', icon: 'settings', label: 'Настройки аккаунта', href: '/profile-settings' } ]; const handleLogout = () => { if (isClient) { localStorage.removeItem('authToken'); localStorage.removeItem('userData'); window.location.href = '/'; } }; const financeItems = [ { id: 'balance', icon: 'wallet', label: 'Баланс', href: '/profile-balance' }, { id: 'requisites', icon: 'case', label: 'Реквизиты', href: '/profile-requisites' }, { id: 'mutual', icon: 'finance_check', label: 'Взаиморасчеты', href: '/profile-mutual' }, { id: 'acts', icon: 'order', label: 'Акты сверки', href: '/profile-acts' } ]; const renderIcon = (iconType: string, isActive: boolean) => { const color = isActive ? '#424F60' : '#424F60'; switch (iconType) { case 'order': return ( ); case 'history': return ( ); case 'bell': return ( ); case 'message': return ( ); case 'location': return ( ); case 'garage': return ( ); case 'settings': return ( ); case 'wallet': return ( ); case 'case': return ( ); case 'finance_check': return ( ); default: return null; } }; return (

Личный кабинет

{menuItems .filter(item => !['notifications', 'messages'].includes(item.id)) // Временно скрываем уведомления и оповещения .map((item) => (
{renderIcon(item.icon, activeItem === item.id)}
{item.label}
))}
{/* Раздел "Финансы" показываем только если есть юридические лица */} {hasLegalEntities && (

Финансы

{financeItems.map((item) => (
{renderIcon(item.icon, activeItem === item.id)}
{item.label}
))}
)} {/* Кнопка выхода */}
); }; export default ProfileSidebar;