11import React from 'react' ;
22import 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
2239export default DashboardStats ;
0 commit comments