Skip to content

Commit 881f2ea

Browse files
Merge pull request djeck1432#944 from laryhills/feat/connect-admin-dashboard-component
2 parents 9d561ef + 1c2c183 commit 881f2ea

2 files changed

Lines changed: 54 additions & 16 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { api } from "../api/api";
3+
4+
interface DashboardStatistics {
5+
users: number;
6+
opened_positions: number;
7+
liquidated_positions: number;
8+
opened_orders: number;
9+
}
10+
11+
const fetchDashboardStatistics = async (): Promise<DashboardStatistics> => {
12+
const response = await api.get("dashboard/statistic").json<DashboardStatistics>();
13+
return response;
14+
};
15+
16+
export const useDashboardStatistics = () => {
17+
return useQuery({
18+
queryKey: ["dashboard", "statistics"],
19+
queryFn: fetchDashboardStatistics,
20+
});
21+
};
Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
import React from 'react';
22
import Card from '../../components/Card';
3+
import { useDashboardStatistics } from '../../../services/dashboardServices';
34

4-
const stats = [
5-
{ label: 'Users', value: 1200 },
6-
{ label: 'Opened Positions', value: 340 },
7-
{ label: 'Liquidated Positions', value: 45 },
8-
{ label: 'Opened Orders', value: 210 },
9-
];
5+
const DashboardStats: React.FC = () => {
6+
const { data: statistics, isLoading, isError } = useDashboardStatistics();
107

11-
const DashboardStats: React.FC = () => (
12-
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
13-
{stats.map((stat) => (
14-
<Card key={stat.label} className="p-6 flex flex-col items-center text-center">
15-
<div className="text-3xl font-bold text-primary mb-2">{stat.value}</div>
16-
<div className="text-lg text-gray-400 font-medium">{stat.label}</div>
17-
</Card>
18-
))}
19-
</div>
20-
);
8+
if (isError) {
9+
return (
10+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
11+
<Card className="p-6 flex flex-col items-center text-center col-span-full">
12+
<div className="text-lg text-red-400 font-medium">Failed to load dashboard statistics</div>
13+
</Card>
14+
</div>
15+
);
16+
}
17+
18+
const stats = [
19+
{ label: 'Users', value: statistics?.users ?? 0 },
20+
{ label: 'Opened Positions', value: statistics?.opened_positions ?? 0 },
21+
{ label: 'Liquidated Positions', value: statistics?.liquidated_positions ?? 0 },
22+
{ label: 'Opened Orders', value: statistics?.opened_orders ?? 0 },
23+
];
24+
25+
return (
26+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
27+
{stats.map((stat) => (
28+
<Card key={stat.label} className="p-6 flex flex-col items-center text-center">
29+
<div className="text-3xl font-bold text-primary mb-2">
30+
{isLoading ? '...' : stat.value.toLocaleString()}
31+
</div>
32+
<div className="text-lg text-gray-400 font-medium">{stat.label}</div>
33+
</Card>
34+
))}
35+
</div>
36+
);
37+
};
2138

2239
export default DashboardStats;

0 commit comments

Comments
 (0)