diff --git a/src/pages/dashboard/DashboardPage.tsx b/src/pages/dashboard/DashboardPage.tsx index 142f87d..8fb9319 100644 --- a/src/pages/dashboard/DashboardPage.tsx +++ b/src/pages/dashboard/DashboardPage.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Card, Col, Row, Statistic, Spin, Alert, Table, Tag } from 'antd'; +import { Card, Col, Row, Statistic, Spin, Alert, Button } from 'antd'; import { UserOutlined, CalendarOutlined, @@ -10,138 +10,99 @@ import { ClockCircleOutlined, DollarOutlined, } from '@ant-design/icons'; +import { Link, useNavigate } from 'react-router-dom'; import { useDashboardStats } from '../../hooks/useDashboard'; -import type { ColumnsType } from 'antd/es/table'; -import { AdminActivity } from '../../types/api'; -import { - AreaChart, - Area, - XAxis, - Tooltip, -} from 'recharts'; +import { useAuthStore } from '../../store/authStore'; import DailyLineChartCard from '../../components/DailyLineChartCard'; +import StatisticSparklineCard from '../../components/StatisticSparklineCard'; const DashboardPage: React.FC = () => { const { data, isLoading, error } = useDashboardStats(); + const role = useAuthStore((s) => s.user?.role); + const navigate = useNavigate(); if (isLoading) return ; if (error) return ; if (!data) return null; - const roleColors: Record = { - superadmin: 'red', - admin: 'blue', - moderator: 'purple', - support: 'cyan', - }; + if (role === 'moderator') { + return ( +
+

Модерация

+ + + } /> + + + + + + } /> + + + +
+ ); + } - const adminColumns: ColumnsType = [ - { title: 'Email', dataIndex: 'email', key: 'email' }, - { title: 'Ник', dataIndex: 'nickname', key: 'nickname' }, - { - title: 'Роль', - dataIndex: 'role', - key: 'role', - render: (role: string) => ( - {role} - ), - }, - { title: 'Действий', dataIndex: 'actions', key: 'actions' }, - { title: 'Последний вход', dataIndex: 'last_login', key: 'last_login' }, - ]; + if (role === 'support') { + return ( +
+

Поддержка

+ + + } /> + + + + + + } /> + + + +
+ ); + } - const eventsChartData = data.events_by_day?.map((item) => ({ + const registrationsSparkline = data.registrations_by_day?.map((item) => ({ date: item.date, - events: item.count, - })) || []; + value: item.count, + })) ?? []; - const registrationsChartData = data.registrations_by_day?.map((item) => ({ + const eventsSparkline = data.events_by_day?.map((item) => ({ date: item.date, - registrations: item.count, - })) || []; + value: item.count, + })) ?? []; return (

Общая статистика

- -
- } - style={{ flex: '0 0 auto', marginRight: 16 }} - /> - {registrationsChartData.length > 0 && ( - - - - - - - - - `Дата: ${label}`} /> - - - )} -
-
+ } + data={registrationsSparkline} + color="#52c41a" + gradientId="colorRegistrations" + /> - -
- } - style={{ flex: '0 0 auto', marginRight: 16 }} - /> - {eventsChartData.length > 0 && ( - - - - - - - - - `Дата: ${label}`} /> - - - )} -
-
+ } + data={eventsSparkline} + color="#1890ff" + gradientId="colorEvents" + /> @@ -240,17 +201,14 @@ const DashboardPage: React.FC = () => {
- {data.admin_activity && data.admin_activity.length > 0 && ( - <> -

Активность администраторов

- - + {role === 'superadmin' && ( + Подробный журнал действий — в разделе Аудит.} + /> )} ); diff --git a/src/types/api.ts b/src/types/api.ts index 0f3d819..39ad43e 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -350,6 +350,11 @@ export interface DashboardStats { tickets_by_day?: DayCount[]; subscriptions_by_day?: DayCount[]; pending_users_by_day?: DayCount[]; + avg_report_resolution_h?: number; + events_moderated?: number; + // support + tickets_assigned_open?: number; + tickets_assigned_total?: number; } export interface AdminActivity {