import IconFont from '@/components/IconFont'; import { apiQueryGroups } from '@/services/master/GroupController'; import { apiQueryLogs } from '@/services/master/LogController'; import { apiSearchThings } from '@/services/master/ThingController'; import { apiQueryUsers } from '@/services/master/UserController'; import { RightOutlined } from '@ant-design/icons'; import { PageContainer, ProCard } from '@ant-design/pro-components'; import { history, useIntl } from '@umijs/max'; import { Button, Col, Divider, Row, Statistic, Typography } from 'antd'; import { useEffect, useState } from 'react'; import CountUp from 'react-countup'; const { Text } = Typography; const ManagerDashboard = () => { const intl = useIntl(); const [counts, setCounts] = useState({ devices: 0, groups: 0, users: 0, logs: 0, }); const [deviceMetadata, setDeviceMetadata] = useState(null); const formatter = (value: number | string) => ( ); useEffect(() => { const fetchData = async () => { try { const [devicesRes, groupsRes, usersRes, logsRes] = await Promise.all([ apiSearchThings({ limit: 1 }), apiQueryGroups({}), apiQueryUsers({ limit: 1 }), apiQueryLogs({ limit: 1 }, 'user_logs'), ]); const devicesTotal = devicesRes?.total || 0; const metadata = (devicesRes as any)?.metadata || null; // Group response handling const groupsTotal = (Array.isArray(groupsRes) ? groupsRes.length : (groupsRes as any)?.total) || 0; const usersTotal = usersRes?.total || 0; const logsTotal = logsRes?.total || 0; setCounts({ devices: devicesTotal, groups: groupsTotal, users: usersTotal, logs: logsTotal, }); setDeviceMetadata(metadata); } catch (error) { console.error('Failed to fetch dashboard counts:', error); } }; fetchData(); }, []); return ( history.push('/manager/devices')} icon={} > Xem chi tiết } > } /> history.push('/manager/groups')} icon={} > Xem chi tiết } > } /> history.push('/manager/users')} icon={} > Xem chi tiết } > } /> history.push('/manager/logs')} icon={} > Xem chi tiết } > } /> {deviceMetadata && ( Kết nối
/{' '} {deviceMetadata.total_thing}
SOS
0 ? '#ff4d4f' : 'inherit', }} >
Bình thường
Cảnh báo
Nghiêm trọng
)}
); }; export default ManagerDashboard;