@@ -71,26 +71,26 @@ const navigate = ( tabId ) => {
71
71
72
72
const quickactions = [
73
73
{
74
- icon : < Icon icon = { bolt } className = "text-info" /> ,
74
+ icon : bolt ,
75
75
title : optimoleDashboardApp . strings . quick_actions . speed_test_title ,
76
76
description : optimoleDashboardApp . strings . quick_actions . speed_test_desc ,
77
77
link : optimoleDashboardApp . strings . quick_actions . speed_test_link ,
78
78
value : 'speedTest'
79
79
} ,
80
80
{
81
- icon : < Icon icon = { update } className = "text-info" /> ,
81
+ icon : update ,
82
82
title : optimoleDashboardApp . strings . quick_actions . clear_cache_images ,
83
83
description : optimoleDashboardApp . strings . quick_actions . clear_cache ,
84
84
value : clearCache
85
85
} ,
86
86
{
87
- icon : < Icon icon = { offloadImage } className = "text-info" /> ,
87
+ icon : offloadImage ,
88
88
title : optimoleDashboardApp . strings . quick_actions . offload_images ,
89
89
description : optimoleDashboardApp . strings . quick_actions . offload_images_desc ,
90
90
value : ( ) => navigate ( settingsTab . offload_image )
91
91
} ,
92
92
{
93
- icon : < Icon icon = { settings } className = "text-info" /> ,
93
+ icon : settings ,
94
94
title : optimoleDashboardApp . strings . quick_actions . advance_settings ,
95
95
description : optimoleDashboardApp . strings . quick_actions . configure_settings ,
96
96
value : ( ) => navigate ( settingsTab . advance )
@@ -137,50 +137,77 @@ const Dashboard = () => {
137
137
138
138
const visitorsLimitPercent = ( ( userData . visitors / userData . visitors_limit ) * 100 ) . toFixed ( 0 ) ;
139
139
140
- const getFormattedMetric = ( metric ) => {
141
- let metricValue = userData [ metric ] ;
140
+ const formatMetric = ( type , value ) => {
141
+ let formattedValue = 0 ;
142
+ let unit = '' ;
142
143
143
144
// Fallback for missing data
144
- if ( undefined === metricValue ) {
145
- metricValue = 'saved_size' === metric ?
146
- Math . floor ( Math . random ( ) * 2500 ) + 500 :
147
- Math . floor ( Math . random ( ) * 40 ) + 10 ;
145
+ if ( undefined === value ) {
146
+ value = 'saved_size' === type ?
147
+ Math . floor ( Math . random ( ) * 2500000 ) + 500000 : // Mock KB
148
+ 'traffic' === type ?
149
+ Math . floor ( Math . random ( ) * 2500 ) + 500 : // Mock MB
150
+ Math . floor ( Math . random ( ) * 40 ) + 10 ; // Mock Percentage
148
151
}
149
152
150
- return metricValue ;
151
- } ;
153
+ switch ( type ) {
154
+ case 'compression_percentage' :
155
+ formattedValue = parseFloat ( value ) . toFixed ( 2 ) ;
156
+ unit = '%' ;
157
+ break ;
158
+ case 'saved_size' : // Assuming value is in KB
159
+ const sizeInMB = value / 1000 ;
160
+ if ( 1000 > sizeInMB ) {
161
+ formattedValue = sizeInMB . toFixed ( 2 ) ;
162
+ unit = 'MB' ;
163
+ } else if ( 1000000 > sizeInMB ) {
164
+ formattedValue = ( sizeInMB / 1000 ) . toFixed ( 2 ) ;
165
+ unit = 'GB' ;
166
+ } else {
167
+ formattedValue = ( sizeInMB / 1000000 ) . toFixed ( 2 ) ;
168
+ unit = 'TB' ;
169
+ }
170
+ break ;
171
+ case 'traffic' : // Assuming value is in MB
172
+ if ( 1000 > value ) {
173
+ formattedValue = parseFloat ( value ) . toFixed ( 2 ) ;
174
+ unit = 'MB' ;
175
+ } else if ( 1000000 > value ) {
176
+ formattedValue = ( value / 1000 ) . toFixed ( 2 ) ;
177
+ unit = 'GB' ;
178
+ } else {
179
+ formattedValue = ( value / 1000000 ) . toFixed ( 2 ) ;
180
+ unit = 'TB' ;
181
+ }
182
+ break ;
183
+ default :
184
+ formattedValue = parseFloat ( value ) . toFixed ( 2 ) ;
185
+ unit = '' ;
186
+ }
152
187
153
- const formatMetricValue = metric => {
154
- const value = getFormattedMetric ( metric ) ;
155
- const calcValue = 'saved_size' === metric ? ( value / 1000 ) . toFixed ( 2 ) : value . toFixed ( 2 ) ;
156
- return (
157
- < div className = 'flex items-end gap-1' >
158
- < span className = 'text-2xl text-black font-bold' > { calcValue } </ span >
159
- < span className = 'text-sm text-gray-500' > { 'compression_percentage' === metric ? '%' : 'MB' } </ span >
160
- </ div >
161
- ) ;
188
+ return { formattedValue, unit } ;
162
189
} ;
163
190
164
191
return (
165
- < >
192
+ < div className = "grid gap-5" >
166
193
< div className = "bg-white p-8 border-0 rounded-lg shadow-md" >
167
194
{ ( 0 < optimoleDashboardApp . strings . notice_just_activated . length && 'active' === userStatus ) && < ActivatedNotice /> }
168
195
169
196
{ 'inactive' === userStatus && < InactiveWarning /> }
170
197
171
- < div className = 'py -6 gap-6 flex-col sm:flex-row items-start sm:items-center ' >
172
- < div className = 'flex w-full justify-between sm:items-center ' >
173
- < div className = "text-gray-800 text-2xl font-bold " >
198
+ < div className = 'pb -6 gap-6 flex-col sm:flex-row items-start' >
199
+ < div className = 'flex flex-col md:flex-row gap-3 w-full justify-between' >
200
+ < div className = "text-gray-800 text-xl font-semibold " >
174
201
{ optimoleDashboardApp . strings . dashboard_title }
175
202
</ div >
176
203
< div className = "flex items-center gap-2" >
177
- < div className = "text-gray-600 text-base font-normal ml-2 " >
204
+ < div className = "text-gray-600 text-base" >
178
205
{ optimoleDashboardApp . strings . quota }
179
206
< span className = "pl-2 text-gray-800 font-bold" >
180
207
{ userData . visitors_pretty } / { userData . visitors_limit_pretty }
181
208
</ span >
182
209
</ div >
183
- < div className = 'w-20' >
210
+ < div className = 'md: w-20 grow md:grow-0 ' >
184
211
< ProgressBar
185
212
value = { userData . visitors }
186
213
max = { userData . visitors_limit }
@@ -197,35 +224,39 @@ const Dashboard = () => {
197
224
'gap-8 flex-col sm:flex-row items-start sm:items-center'
198
225
) }
199
226
>
200
- < div >
201
- < div className = "text-gray-800 text-xl font-bold " >
227
+ < div className = "grid gap-2" >
228
+ < div className = "text-gray-700 text-lg font-semibold " >
202
229
{ optimoleDashboardApp . strings . banner_title }
203
230
</ div >
204
- < div className = "text-gray-600 text-base " >
231
+ < div className = "text-gray-600 text-sm " >
205
232
{ optimoleDashboardApp . strings . banner_description }
206
233
</ div >
207
234
</ div >
208
235
</ div >
209
236
210
- < div className = "flex py -5 gap-5 flex-col md:flex-row" >
237
+ < div className = "flex pt -5 gap-5 flex-col md:flex-row" >
211
238
{ metrics . map ( metric => {
239
+ const rawValue = userData [ metric . value ] ;
240
+ const { formattedValue, unit } = formatMetric ( metric . value , rawValue ) ;
241
+
212
242
return (
213
243
< div
214
244
key = { metric . value }
215
245
className = { classNames (
216
- 'p-3 basis-1/3 flex-col items-start border rounded-md border-solid bg-white border-light- gray border-slate-400 '
246
+ 'p-3 basis-1/3 flex-col items-start border rounded-md border-solid bg-white border-gray-300 '
217
247
) }
218
248
>
219
249
< div className = "flex w-full flex-col" >
220
- < div className = "not-italic font-normal text-sm text-gray-500" >
250
+ < div className = "text-sm text-gray-500" >
221
251
{ metric . label }
222
252
</ div >
223
253
224
- < div >
225
- { formatMetricValue ( metric . value ) }
254
+ < div className = 'flex items-end gap-1' >
255
+ < span className = 'text-2xl text-black font-bold' > { formattedValue } </ span >
256
+ < span className = 'text-sm text-gray-500' > { unit } </ span >
226
257
</ div >
227
258
228
- < div className = "font-normal text-sm text- gray-600" >
259
+ < div className = "font-normal text-gray-600" >
229
260
{ metric . description }
230
261
</ div >
231
262
</ div >
@@ -234,39 +265,42 @@ const Dashboard = () => {
234
265
} ) }
235
266
</ div >
236
267
</ div >
237
- < div className = "my-3 bg-white p-8 border-0 rounded-lg shadow-md" >
238
- < div className = "text-gray-800 font-bold text-2xl" > { optimoleDashboardApp . strings . quick_action_title } </ div >
239
- < div className = "grid grid-cols-1 md:grid-cols-2 gap-5 py-5" >
240
- { quickactions . map ( ( action , index ) => (
241
- < div
242
- key = { index }
243
- className = "flex items-start items-center gap-3 p-4 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors"
244
- >
245
- { action . icon }
246
- < div className = "flex flex-col" >
247
- < span className = "font-medium text-base text-gray-800" > { action . title } </ span >
248
- { 'speedTest' === action . value ? (
249
- < a href = { action . link } target = "_blank" className = "text-info text-sm font-medium hover:text-info" > { action . description } </ a >
250
- ) : (
251
- < Button
252
- variant = "default"
253
- className = "text-info text-sm font-medium p-0 h-5 focus:!shadow-none focus:!outline-none"
254
- onClick = { ( ) => action . value ( ) }
255
- >
256
- { action . description }
257
- </ Button >
258
- ) }
259
- </ div >
260
- </ div >
261
- ) ) }
268
+ < div className = "bg-white p-8 border-0 rounded-lg shadow-md" >
269
+ < div className = "text-gray-800 text-xl font-semibold mb-5" > { optimoleDashboardApp . strings . quick_action_title } </ div >
270
+ < div className = "grid md:grid-cols-2 gap-5" >
271
+ { quickactions . map ( ( action , index ) => {
272
+
273
+ const TAG = 'speedTest' === action . value ? 'a' : 'button' ;
274
+ const additionalProps = 'speedTest' === action . value ? {
275
+ href : action . link ,
276
+ target : '_blank'
277
+ } : {
278
+ onClick : ( ) => {
279
+ action . value ( ) ;
280
+ }
281
+ } ;
282
+ return (
283
+ < TAG
284
+ key = { index }
285
+ className = "flex items-center gap-3 p-4 bg-gray-50 rounded-lg hover:bg-light-blue hover:bg-info hover:border-info transition-background duration-300 group shadow-none border-gray-200 border border-solid cursor-pointer"
286
+ { ...additionalProps }
287
+ >
288
+ < Icon icon = { action . icon } className = "text-info" />
289
+ < div className = "flex flex-col items-start gap-1" >
290
+ < span className = "font-medium text-base text-gray-800" > { action . title } </ span >
291
+ < span className = "text-info text-sm font-medium hover:text-info" > { action . description } </ span >
292
+ </ div >
293
+ </ TAG >
294
+ ) ;
295
+ } ) }
262
296
</ div >
263
297
</ div >
264
- < div className = "bg-white p-8 border-0 rounded-lg shadow-md" >
298
+ < div className = "bg-white p-8 border-0 rounded-lg shadow-md hidden lg:block " >
265
299
{ 'yes' !== optimoleDashboardApp . remove_latest_images && (
266
300
< LastImages />
267
301
) }
268
302
</ div >
269
- </ >
303
+ </ div >
270
304
) ;
271
305
} ;
272
306
0 commit comments