diff --git a/src/api/monthlyOrders.ts b/src/api/monthlyOrders.ts index d4ec922..4e056ad 100644 --- a/src/api/monthlyOrders.ts +++ b/src/api/monthlyOrders.ts @@ -16,7 +16,6 @@ export interface AdminUser { } export const monthlyOrdersApi = { - // 🟢 Теперь функция умеет принимать ID менеджера getMatrix: (managerId?: number) => { const url = managerId ? `/monthly-orders/matrix?manager_id=${managerId}` : '/monthly-orders/matrix'; return apiClient.get(url); @@ -28,4 +27,7 @@ export const monthlyOrdersApi = { // 🟢 Метод для аналитика: получить всех сотрудников getManagersList: () => apiClient.get<{ data: AdminUser[] }>('/admin?limit=100'), + + exportToGoogle: (email: string) => + apiClient.post<{ url: string }>('/monthly-orders/report/google', { email }), }; \ No newline at end of file diff --git a/src/pages/AnalystDashboard.tsx b/src/pages/AnalystDashboard.tsx index 6b7bef0..330e893 100644 --- a/src/pages/AnalystDashboard.tsx +++ b/src/pages/AnalystDashboard.tsx @@ -1,13 +1,20 @@ import { useEffect, useState } from 'react'; -import { Container, Title, SimpleGrid, Card, Text, Button, LoadingOverlay, Badge, Group } from '@mantine/core'; +import { Container, Title, SimpleGrid, Card, Text, Button, LoadingOverlay, Badge, Group, TextInput, Anchor, Alert } from '@mantine/core'; import { useNavigate } from 'react-router-dom'; import { monthlyOrdersApi } from '../api/monthlyOrders'; -import type { AdminUser } from '../api/monthlyOrders'; -import { IconTable } from '@tabler/icons-react'; +import type { AdminUser } from '../api/monthlyOrders'; // Используем type-only import для строгого режима TS +import { IconTable, IconFileExport } from '@tabler/icons-react'; +import { notifications } from '@mantine/notifications'; export default function AnalystDashboard() { const [users, setUsers] = useState([]); const [loading, setLoading] = useState(true); + + // Стейты для выгрузки отчета + const [email, setEmail] = useState(''); + const [isExporting, setIsExporting] = useState(false); + const [reportUrl, setReportUrl] = useState(null); + const navigate = useNavigate(); useEffect(() => { @@ -17,21 +24,79 @@ export default function AnalystDashboard() { .finally(() => setLoading(false)); }, []); + // Оставляем ТОЛЬКО менеджеров (у которых нет особых ролей и есть привязанный профиль Telegram) const managers = users.filter(u => !u.is_analyst && !u.is_root && !u.is_observer && u.telegram_user?.id); + const handleExport = async () => { + if (!email.includes('@')) { + return notifications.show({ title: 'Ошибка', message: 'Введите корректный email', color: 'red' }); + } + setIsExporting(true); + setReportUrl(null); + try { + const res = await monthlyOrdersApi.exportToGoogle(email); + setReportUrl(res.data.url); + notifications.show({ title: 'Успех', message: 'Отчет успешно сгенерирован!', color: 'green' }); + } catch (err: any) { + notifications.show({ + title: 'Ошибка', + message: err.response?.data?.error_description || 'Не удалось создать отчет', + color: 'red' + }); + } finally { + setIsExporting(false); + } + }; + if (loading) return ; return ( - Панель аналитика - Выберите менеджера для просмотра его таблицы заказов: + + Панель аналитика + + + {/* Блок выгрузки сводного отчета */} + + Сводный отчет за текущий месяц + + Укажите Google-почту, на которую необходимо выдать права доступа. Отчет будет сгенерирован в виде таблицы и будет содержать все заказы и комментарии менеджеров. + + + setEmail(e.currentTarget.value)} + /> + + + + {reportUrl && ( + + + Открыть сгенерированную таблицу + + + )} + + + {/* Сетка менеджеров */} + Выберите менеджера для детального просмотра его матрицы: {managers.length === 0 ? ( Менеджеры не найдены. ) : ( {managers.map(u => { - // Имя берем из привязанного Telegram профиля, если его нет - из админки const displayName = u.telegram_user?.full_name || u.name || u.login; return ( @@ -50,7 +115,6 @@ export default function AnalystDashboard() { fullWidth radius="md" leftSection={} - // 🟢 КРИТИЧЕСКИЙ ФИКС: Передаем правильный ID (User.ID, а не Admin.ID) onClick={() => navigate(`/manager/${u.telegram_user!.id}`)} > Смотреть заказы