import * as React from "react"; import { useEffect, useState } from "react"; import { useRouter } from "next/router"; import { useQuery } from '@apollo/client'; import { GET_CLIENT_ME } from '@/lib/graphql'; import Header from '@/components/Header'; import Footer from '@/components/Footer'; import ProfileSidebar from '@/components/ProfileSidebar'; import CatalogSubscribe from '@/components/CatalogSubscribe'; import MobileMenuBottomSection from "@/components/MobileMenuBottomSection"; import LKMenu from '@/components/LKMenu'; import ProfileActsMain from '@/components/profile/ProfileActsMain'; import ProfileInfo from '@/components/profile/ProfileInfo'; import NotificationMane from "@/components/profile/NotificationMane"; import MetaTags from "../components/MetaTags"; import { getMetaByPath } from "../lib/meta-config"; const ProfileActsPage = () => { const router = useRouter(); const [isAuthenticated, setIsAuthenticated] = useState(false); const { data: clientData, loading: clientLoading } = useQuery(GET_CLIENT_ME, { skip: !isAuthenticated, onCompleted: (data) => { // Проверяем есть ли у клиента юридические лица if (!data?.clientMe?.legalEntities?.length) { // Если нет юридических лиц, перенаправляем на настройки router.push('/profile-settings?tab=legal'); return; } }, onError: (error) => { console.error('Ошибка загрузки данных клиента:', error); // Если ошибка авторизации, перенаправляем на главную router.push('/'); } }); useEffect(() => { // Проверяем авторизацию const token = localStorage.getItem('authToken'); if (!token) { router.push('/'); return; } setIsAuthenticated(true); }, [router]); // Показываем загрузку пока проверяем авторизацию и данные if (!isAuthenticated || clientLoading) { return (
Загрузка...
); } return ( <>