import { Navigate, useNavigate, Link } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { Crown, Search, Shield, BookOpen, ShieldAlert, Settings as SettingsIcon } from 'lucide-react'; import toast from 'react-hot-toast'; import { TaskCard } from '../components/TaskCard'; import { tasksApi, adminApi } from '../api/client'; import { useAuthStore } from '../store/auth'; import { PLAN_LIMITS, type Task } from '../types'; const PLAN_BADGE_STYLES = { free: 'bg-gray-100 text-gray-600', student: 'bg-blue-100 text-blue-700', premium: 'bg-purple-100 text-purple-700', science: 'bg-amber-100 text-amber-700', }; export function Cabinet() { const { isAuthenticated, user } = useAuthStore(); const navigate = useNavigate(); const openAdmin = async () => { try { const { data } = await adminApi.openSession(); navigate(`${data.url}/dashboard`); } catch { toast.error('Не удалось открыть админ-панель'); } }; if (!isAuthenticated) { return ; } const { data: tasks, isLoading } = useQuery({ queryKey: ['tasks'], queryFn: () => tasksApi.list().then((r) => r.data as Task[]), refetchInterval: 10000, }); const plan = user?.plan || 'free'; const planInfo = PLAN_LIMITS[plan as keyof typeof PLAN_LIMITS]; return (
{/* Профиль */}
{user?.name?.[0]?.toUpperCase() || 'U'}

{user?.name}

{planInfo.name}

{user?.email}

Настройки {user?.is_admin && ( )}
{/* Лимиты */}
{[ { icon: Search, label: 'Поисков/день', value: planInfo.search_per_day, color: 'text-blue-600', bg: 'bg-blue-50', }, { icon: Shield, label: 'Проверок/мес', value: planInfo.plagiarism_per_month, color: 'text-purple-600', bg: 'bg-purple-50', }, { icon: BookOpen, label: 'Изложений/мес', value: planInfo.summarize_per_month, color: 'text-emerald-600', bg: 'bg-emerald-50', }, { icon: Crown, label: 'Одновременно', value: planInfo.concurrent, color: 'text-amber-600', bg: 'bg-amber-50', }, ].map(({ icon: Icon, label, value, color, bg }) => (
{value === null ? '∞' : value}
{label}
))}
{/* Задачи */}

Мои задачи {tasks && `(${tasks.length})`}

{isLoading && (
{[1, 2, 3].map((i) => (
))}
)} {tasks && tasks.length > 0 && (
{tasks.map((task) => ( ))}
)} {tasks && tasks.length === 0 && (

Задач пока нет. Начните с поиска источников!

)}
); }