11import useDirDetection from '@/hooks/use-dir-detection'
22import { cn } from '@/lib/utils.ts'
3- import { numberWithCommas } from '@/utils/formatByte'
43import { useTranslation } from 'react-i18next'
54import { Card , CardTitle } from '@/components/ui/card'
5+ import { CountUp } from '@/components/ui/count-up'
66import { type AdminDetails } from '@/service/api'
77import { User , UserCheck , UserX } from 'lucide-react'
8- import React from 'react'
8+ import React , { useEffect , useState } from 'react'
99
1010interface AdminsStatisticsProps {
1111 data : AdminDetails [ ]
@@ -14,28 +14,48 @@ interface AdminsStatisticsProps {
1414export default function AdminStatisticsSection ( { data } : AdminsStatisticsProps ) {
1515 const { t } = useTranslation ( )
1616 const dir = useDirDetection ( )
17+ const [ prevStats , setPrevStats ] = useState < { total : number ; active : number ; disabled : number } | null > ( null )
18+ const [ isIncreased , setIsIncreased ] = useState < Record < string , boolean > > ( { } )
19+
1720 const total = data . length
1821 const disabled = data . filter ( a => a . is_disabled ) . length
1922 const active = total - disabled
2023
24+ const currentStats = { total, active, disabled }
25+
26+ useEffect ( ( ) => {
27+ if ( prevStats ) {
28+ setIsIncreased ( {
29+ total : currentStats . total > prevStats . total ,
30+ active : currentStats . active > prevStats . active ,
31+ disabled : currentStats . disabled > prevStats . disabled ,
32+ } )
33+ }
34+ setPrevStats ( currentStats )
35+ // eslint-disable-next-line react-hooks/exhaustive-deps
36+ } , [ data ] )
37+
2138 const stats = [
2239 {
2340 icon : User ,
2441 label : t ( 'admins.total' ) ,
2542 value : total ,
2643 color : '' ,
44+ key : 'total' ,
2745 } ,
2846 {
2947 icon : UserCheck ,
3048 label : t ( 'admins.active' ) ,
3149 value : active ,
3250 color : '' ,
51+ key : 'active' ,
3352 } ,
3453 {
3554 icon : UserX ,
3655 label : t ( 'admins.disable' ) ,
3756 value : disabled ,
3857 color : '' ,
58+ key : 'disabled' ,
3959 } ,
4060 ]
4161
@@ -64,8 +84,15 @@ export default function AdminStatisticsSection({ data }: AdminsStatisticsProps)
6484 { React . createElement ( stat . icon , { className : 'h-6 w-6' } ) }
6585 < span > { stat . label } </ span >
6686 </ div >
67- < span className = "text-3xl font-bold" dir = "ltr" >
68- { numberWithCommas ( stat . value ) }
87+ < span
88+ className = { cn (
89+ 'mx-2 text-3xl font-bold transition-all duration-500' ,
90+ isIncreased [ stat . key ] ? 'animate-zoom-out' : ''
91+ ) }
92+ style = { { animationDuration : '400ms' } }
93+ dir = "ltr"
94+ >
95+ < CountUp end = { stat . value } />
6996 </ span >
7097 </ CardTitle >
7198 </ Card >
0 commit comments