import * as React from "react"; import Link from 'next/link'; import { useRouter } from 'next/router'; import { useQuery } from '@apollo/client'; import { useIsClient } from '@/lib/useIsomorphicLayoutEffect'; import { GET_CLIENT_ME } from '@/lib/graphql'; const menuItems = [ { label: 'Заказы', href: '/profile-orders', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/22ecd7e6251abe04521d03f0ac09f73018a8c2c8?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'История поиска', href: '/profile-history', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/e7688217cca08e8c080ec07f80bf1142429d899c?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Уведомления', href: '/profile-announcement', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/7505ecbdf10660110c88e1641f43b4618fef292d?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Оповещения', href: '/profile-notification', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/f7a4dd35c3365eb1f1e7292f9b6194b8a3083c4f?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Адреса доставки', href: '/profile-addresses', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/1faca7190a7dd71a66fd3cf0127a8c6e45eac5e6?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Гараж', href: '/profile-gar', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/783501855b4cb8be4ac47a0733e298c3f3ccfc5e?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Настройки аккаунта', href: '/profile-set', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/b39907028aa6baf08adc313aed84d1294f2be013?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Настройки cookies', href: '/profile-cookie-settings', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/b39907028aa6baf08adc313aed84d1294f2be013?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, ]; const financeItems = [ { label: 'Баланс', href: '/profile-balance', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/135ee20623aaa1f29816106bd0ca1a627976969d?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Реквизиты', href: '/profile-req', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/0890fb36a7fb89b3942f93be72ac0e79d93bc530?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, // { label: 'Взаиморасчеты', href: '/profile-settlements', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/74b08742b16c7daefb4d895173a6d749eb61fd94?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, { label: 'Акты сверки', href: '/profile-acts', icon: 'https://cdn.builder.io/api/v1/image/assets/TEMP/22ecd7e6251abe04521d03f0ac09f73018a8c2c8?placeholderIfAbsent=true&apiKey=f5bc5a2dc9b841d0aba1cc6c74a35920' }, ]; function normalizePath(path: string) { return path.replace(/\/+$/, ''); } const LKMenu = React.forwardRef((props, ref) => { const router = useRouter(); 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 handleLogout = () => { if (isClient) { localStorage.removeItem('authToken'); localStorage.removeItem('userData'); window.location.href = '/'; } }; return (
Личный кабинет
{menuItems .filter(item => !['Уведомления', 'Оповещения'].includes(item.label)) // Временно скрываем эти пункты .map((item) => { const isActive = normalizePath(router.asPath) === normalizePath(item.href); return (
{item.label}
{item.label}
); })}
{/* Раздел "Финансы" показываем только если есть юридические лица */} {hasLegalEntities && ( <>
Финансы
{financeItems.map((item) => { const isActive = normalizePath(router.asPath) === normalizePath(item.href); return (
{item.label}
{item.label}
); })}
)} {/* Кнопка выхода */}
); }); LKMenu.displayName = 'LKMenu'; export default LKMenu;