Skip to content

Commit

Permalink
Update WebsiteMetricsBar.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
quiple committed Aug 29, 2024
1 parent a76bb4b commit 5ae04f4
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/app/(main)/websites/[websiteId]/WebsiteMetricsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { useDateRange, useMessages, useSticky } from 'components/hooks';
import { useDateRange, useLocale, useMessages, useSticky } from 'components/hooks';
import WebsiteDateFilter from 'components/input/WebsiteDateFilter';
import MetricCard from 'components/metrics/MetricCard';
import MetricsBar from 'components/metrics/MetricsBar';
Expand Down Expand Up @@ -33,8 +33,18 @@ export function WebsiteMetricsBar({
compareMode && dateCompare,
);
const isAllTime = dateRange.value === 'all';
const { locale } = useLocale();
const intl = useIntl();

const minimum = {
'de-CH': 1000000,
'de-DE': 1000000,
'it-IT': 1000000,
'ja-JP': 10000,
'zh-CN': 10000,
'zh-TW': 10000,
};

const { pageviews, visitors, visits, bounces, totaltime } = data || {};
const optionsNumber: FormatNumberOptions = { notation: 'compact', maximumFractionDigits: 2 };
const optionsSmallNumber: FormatNumberOptions = { notation: 'compact' };
Expand All @@ -47,21 +57,30 @@ export function WebsiteMetricsBar({
label: formatMessage(labels.views),
change: pageviews.value - pageviews.prev,
formatValue: (n: number) =>
intl.formatNumber(+n, +n < 1000 ? optionsSmallNumber : optionsNumber),
intl.formatNumber(
+n,
+n < (minimum[locale] || 1000) ? optionsSmallNumber : optionsNumber,
),
},
{
...visits,
label: formatMessage(labels.visits),
change: visits.value - visits.prev,
formatValue: (n: number) =>
intl.formatNumber(+n, +n < 1000 ? optionsSmallNumber : optionsNumber),
intl.formatNumber(
+n,
+n < (minimum[locale] || 1000) ? optionsSmallNumber : optionsNumber,
),
},
{
...visitors,
label: formatMessage(labels.visitors),
change: visitors.value - visitors.prev,
formatValue: (n: number) =>
intl.formatNumber(+n, +n < 1000 ? optionsSmallNumber : optionsNumber),
intl.formatNumber(
+n,
+n < (minimum[locale] || 1000) ? optionsSmallNumber : optionsNumber,
),
},
{
label: formatMessage(labels.bounceRate),
Expand Down

0 comments on commit 5ae04f4

Please sign in to comment.