Skip to content

Commit b5564ee

Browse files
authored
Merge pull request #966 from Codeinwp/feat/monthly_visit
feat: helper text for 'visits' metric
2 parents be4b22f + 73ea28e commit b5564ee

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

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

Lines changed: 53 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,37 @@ 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 className="p-2.5 max-w-[320px]">
228+
<div className="font-bold mb-2">
229+
{ optimoleDashboardApp.strings.tooltip_visits_title }
230+
</div>
231+
<div>
232+
{
233+
sprintf(
234+
optimoleDashboardApp.strings.tooltip_visits_description,
235+
renewalDate
236+
)
237+
}
238+
</div>
239+
</div>
240+
}
241+
placement="bottom"
242+
>
243+
<span className="inline-flex items-center cursor-help ml-1">
244+
<Icon
245+
icon={ help }
246+
size={ 18 }
247+
className="text-gray-400 hover:text-gray-600"
248+
/>
249+
</span>
250+
</Tooltip>
210251
</div>
211252
<div className='md:w-20 grow md:grow-0'>
212253
<ProgressBar
@@ -215,6 +256,14 @@ const Dashboard = () => {
215256
/>
216257
</div>
217258
<span>{ visitorsLimitPercent }%</span>
259+
<span className="text-gray-500 text-sm ml-2">
260+
{
261+
sprintf(
262+
optimoleDashboardApp.strings.renew_date,
263+
renewalDate
264+
)
265+
}
266+
</span>
218267
</div>
219268
</div>
220269
</div>

inc/admin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,9 @@ private function get_dashboard_strings() {
15961596
'not_connected' => __( 'NOT CONNECTED', 'optimole-wp' ),
15971597
'usage' => __( 'Monthly Usage', 'optimole-wp' ),
15981598
'quota' => __( 'Monthly visits:', 'optimole-wp' ),
1599+
'tooltip_visits_title' => __( 'What are visits?', 'optimole-wp' ),
1600+
/* translators: 1 is the day when the visits reset, for example 1st of each month */
1601+
'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' ),
15991602
'logged_in_as' => __( 'LOGGED IN AS', 'optimole-wp' ),
16001603
'private_cdn_url' => __( 'IMAGES DOMAIN', 'optimole-wp' ),
16011604
'existing_user' => __( 'Existing user?', 'optimole-wp' ),
@@ -2152,6 +2155,8 @@ private function get_dashboard_strings() {
21522155
'<a class="flex justify-center items-center font-semibold" href="https://docs.optimole.com/article/2238-optimization-tips" target="_blank"> ',
21532156
'<span style="text-decoration:none; font-size:15px; margin-top:2px;" class="dashicons dashicons-external"></span></a>'
21542157
),
2158+
// translators: %s is the date of the renewal.
2159+
'renew_date' => __( 'Renews %s', 'optimole-wp' ),
21552160
];
21562161
}
21572162

0 commit comments

Comments
 (0)