2023-04-14 07:28:29 +02:00
|
|
|
import FilterLink from 'components/common/FilterLink';
|
2023-07-08 21:07:37 +02:00
|
|
|
import { emptyFilter } from 'lib/filters';
|
2023-08-21 11:06:09 +02:00
|
|
|
import useLocale from 'components/hooks/useLocale';
|
|
|
|
import useMessages from 'components/hooks/useMessages';
|
|
|
|
import useCountryNames from 'components/hooks/useCountryNames';
|
2023-07-08 21:07:37 +02:00
|
|
|
import MetricsTable from './MetricsTable';
|
2023-08-22 04:32:17 +02:00
|
|
|
import regions from 'public/iso-3166-2.json';
|
2023-04-14 07:28:29 +02:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function RegionsTable({ websiteId, ...props }) {
|
2023-04-14 07:28:29 +02:00
|
|
|
const { locale } = useLocale();
|
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-04-21 23:35:00 +02:00
|
|
|
const countryNames = useCountryNames(locale);
|
2023-04-14 07:28:29 +02:00
|
|
|
|
2023-08-28 08:30:46 +02:00
|
|
|
const renderLabel = (code, country) => {
|
|
|
|
const region = code.includes('-') ? code : `${country}-${code}`;
|
|
|
|
return regions[region] ? `${regions[region]}, ${countryNames[country]}` : region;
|
2023-04-21 23:35:00 +02:00
|
|
|
};
|
|
|
|
|
2023-08-28 08:30:46 +02:00
|
|
|
const renderLink = ({ x: code, country }) => {
|
2023-04-14 07:28:29 +02:00
|
|
|
return (
|
2023-08-28 08:30:46 +02:00
|
|
|
<FilterLink id="region" className={locale} value={code} label={renderLabel(code, country)}>
|
2023-09-29 14:29:22 +02:00
|
|
|
<img
|
|
|
|
src={`${process.env.basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
|
|
|
|
alt={code}
|
|
|
|
/>
|
2023-04-24 04:52:44 +02:00
|
|
|
</FilterLink>
|
2023-04-14 07:28:29 +02:00
|
|
|
);
|
2023-04-21 23:35:00 +02:00
|
|
|
};
|
2023-04-14 07:28:29 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<MetricsTable
|
|
|
|
{...props}
|
|
|
|
title={formatMessage(labels.regions)}
|
|
|
|
type="region"
|
|
|
|
metric={formatMessage(labels.visitors)}
|
|
|
|
websiteId={websiteId}
|
|
|
|
dataFilter={emptyFilter}
|
|
|
|
renderLabel={renderLink}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default RegionsTable;
|