Skip to content

Commit 02eb5e7

Browse files
feat: helper text for 'visits' metric
1 parent be5a6d5 commit 02eb5e7

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

assets/src/dashboard/parts/connected/dashboard/index.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import classNames from 'classnames';
88
*/
99
import {
1010
Button,
11-
Icon
11+
Icon,
12+
Tooltip
1213
} from '@wordpress/components';
1314

15+
import { sprintf } from '@wordpress/i18n';
16+
1417
import { useSelect } from '@wordpress/data';
15-
import { warning } from '@wordpress/icons';
18+
import { warning, help } from '@wordpress/icons';
1619

1720
import { clearCache } from '../../../utils/api';
1821

@@ -30,6 +33,7 @@ import ProgressBar from '../../components/ProgressBar';
3033
import DashboardMetricBox from '../../components/DashboardMetricBox';
3134

3235
import LastImages from './LastImages';
36+
import { useMemo } from 'react';
3337

3438
const cardClasses = 'flex p-6 bg-light-blue border border-blue-300 rounded-md';
3539

@@ -138,6 +142,17 @@ const Dashboard = () => {
138142

139143
const visitorsLimitPercent = ( ( userData.visitors / userData.visitors_limit ) * 100 ).toFixed( 0 );
140144

145+
const renewalDate = useMemo( () => {
146+
const timestamp = userData.renews_on;
147+
148+
if ( ! timestamp ) {
149+
return 'N/A';
150+
}
151+
152+
const date = new Date( timestamp * 1000 );
153+
return date.toLocaleDateString( undefined, { year: 'numeric', month: 'short', day: 'numeric' });
154+
}, [ userData.renews_on ]);
155+
141156
const formatMetric = ( type, value ) => {
142157
let formattedValue = 0;
143158
let unit = '';
@@ -202,11 +217,40 @@ const Dashboard = () => {
202217
{ optimoleDashboardApp.strings.dashboard_title }
203218
</div>
204219
<div className="flex items-center gap-2">
205-
<div className="text-gray-600 text-base">
220+
<div className="text-gray-600 text-base flex items-center gap-1">
206221
{ optimoleDashboardApp.strings.quota }
207-
<span className="pl-2 text-gray-800 font-bold">
222+
<span className="text-gray-800 font-bold">
208223
{ userData.visitors_pretty } / { userData.visitors_limit_pretty }
209224
</span>
225+
<Tooltip
226+
text={
227+
<div style={{
228+
padding: '10px',
229+
maxWidth: '320px'
230+
}}>
231+
<div style={{ fontWeight: 'bold', marginBottom: '8px' }}>
232+
{ optimoleDashboardApp.strings.tooltip_visits_title }
233+
</div>
234+
<div>
235+
{
236+
sprintf(
237+
optimoleDashboardApp.strings.tooltip_visits_description,
238+
renewalDate
239+
)
240+
}
241+
</div>
242+
</div>
243+
}
244+
placement="bottom"
245+
>
246+
<span className="inline-flex items-center cursor-help ml-1">
247+
<Icon
248+
icon={ help }
249+
size={ 18 }
250+
className="text-gray-400 hover:text-gray-600"
251+
/>
252+
</span>
253+
</Tooltip>
210254
</div>
211255
<div className='md:w-20 grow md:grow-0'>
212256
<ProgressBar
@@ -215,6 +259,14 @@ const Dashboard = () => {
215259
/>
216260
</div>
217261
<span>{ visitorsLimitPercent }%</span>
262+
<span className="text-gray-500 text-sm ml-2">
263+
{
264+
sprintf(
265+
optimoleDashboardApp.strings.renew_date,
266+
renewalDate
267+
)
268+
}
269+
</span>
218270
</div>
219271
</div>
220272
</div>

inc/admin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,8 @@ private function get_dashboard_strings() {
15771577
'not_connected' => __( 'NOT CONNECTED', 'optimole-wp' ),
15781578
'usage' => __( 'Monthly Usage', 'optimole-wp' ),
15791579
'quota' => __( 'Monthly visits:', 'optimole-wp' ),
1580+
'tooltip_visits_title' => __( 'What are visits?', 'optimole-wp' ),
1581+
'tooltip_visits_description' => __( 'Each visitor to your site is counted as a unique daily user, regardless of their actions or return visits on the same day. Your visit count resets on %s.', 'optimole-wp' ),
15801582
'logged_in_as' => __( 'LOGGED IN AS', 'optimole-wp' ),
15811583
'private_cdn_url' => __( 'IMAGES DOMAIN', 'optimole-wp' ),
15821584
'existing_user' => __( 'Existing user?', 'optimole-wp' ),
@@ -2143,6 +2145,8 @@ private function get_dashboard_strings() {
21432145
'<a class="flex justify-center items-center font-semibold" href="https://docs.optimole.com/article/2238-optimization-tips" target="_blank"> ',
21442146
'<span style="text-decoration:none; font-size:15px; margin-top:2px;" class="dashicons dashicons-external"></span></a>'
21452147
),
2148+
// translators: %s is the date of the renewal.
2149+
'renew_date' => __( 'Renews %s', 'optimole-wp' ),
21462150
];
21472151
}
21482152

0 commit comments

Comments
 (0)