@@ -26,6 +26,7 @@ import {
2626} from '../../../utils/icons' ;
2727
2828import ProgressBar from '../../components/ProgressBar' ;
29+ import DashboardMetricBox from '../../components/DashboardMetricBox' ;
2930
3031import LastImages from './LastImages' ;
3132
@@ -98,34 +99,30 @@ const Dashboard = () => {
9899
99100 const visitorsLimitPercent = ( ( userData . visitors / userData . visitors_limit ) * 100 ) . toFixed ( 0 ) ;
100101
101- const getMetricValue = metric => {
102- if ( undefined !== userData [ metric ] ) {
103- return userData [ metric ] ;
104- }
102+ const getFormattedMetric = ( metric ) => {
103+ let metricValue = userData [ metric ] ;
105104
106- if ( 'saved_size' === metric ) {
107- return Math . floor ( Math . random ( ) * 2500 ) + 500 ;
105+ // Fallback for missing data
106+ if ( undefined === metricValue ) {
107+ metricValue = 'saved_size' === metric ?
108+ Math . floor ( Math . random ( ) * 2500 ) + 500 :
109+ Math . floor ( Math . random ( ) * 40 ) + 10 ;
108110 }
109111
110- return Math . floor ( Math . random ( ) * 40 ) + 10 ;
111- } ;
112-
113- const formatMetricValue = metric => {
114- const value = getMetricValue ( metric ) ;
115-
112+ // Format based on metric type
116113 if ( 'saved_size' === metric ) {
117- return ( value / 1000 ) . toFixed ( 2 ) + 'MB' ;
114+ return ( metricValue / 1000 ) . toFixed ( 2 ) + 'MB' ;
118115 }
119116
120117 if ( 'compression_percentage' === metric ) {
121- return value . toFixed ( 2 ) + '%' ;
118+ return metricValue . toFixed ( 2 ) + '%' ;
122119 }
123120
124121 if ( 'traffic' === metric ) {
125- return value . toFixed ( 2 ) + 'MB' ;
122+ return metricValue . toFixed ( 2 ) + 'MB' ;
126123 }
127124
128- return value ;
125+ return metricValue ;
129126 } ;
130127
131128 return (
@@ -188,31 +185,15 @@ const Dashboard = () => {
188185 < div className = "flex py-5 gap-5 flex-col md:flex-row" >
189186 { metrics . map ( metric => {
190187 return (
191- < div
188+ < DashboardMetricBox
192189 key = { metric . value }
193- className = { classNames (
194- cardClasses ,
195- 'basis-1/4 flex-col items-start'
196- ) }
197- >
198- < Icon icon = { metric . icon } />
199-
200- < div className = "flex w-full flex-col" >
201- < div className = "not-italic font-bold text-xl py-2 text-gray-800" >
202- { formatMetricValue ( metric . value ) }
203- </ div >
204-
205- < div className = "not-italic font-normal text-sm text-gray-800" >
206- { metric . label }
207- </ div >
208-
209- < div className = "font-normal text-xs text-gray-600" >
210- { metric . description }
211- </ div >
212- </ div >
213- </ div >
190+ value = { getFormattedMetric ( metric . value ) }
191+ label = { metric . label }
192+ description = { metric . description }
193+ icon = { metric . icon }
194+ />
214195 ) ;
215- } ) }
196+ } ) }
216197 </ div >
217198
218199 { 'yes' !== optimoleDashboardApp . remove_latest_images && (
0 commit comments