2023-02-18 06:42:42 +01:00
|
|
|
import { useCallback } from 'react';
|
2023-07-13 17:37:51 +02:00
|
|
|
import { useRouter } from 'next/router';
|
2023-02-18 06:42:42 +01:00
|
|
|
import DataTable from 'components/metrics/DataTable';
|
|
|
|
import useLocale from 'hooks/useLocale';
|
|
|
|
import useCountryNames from 'hooks/useCountryNames';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-07-13 17:37:51 +02:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import styles from './RealtimeCountries.module.css';
|
2023-02-18 06:42:42 +01:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function RealtimeCountries({ data }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-02-18 06:42:42 +01:00
|
|
|
const { locale } = useLocale();
|
|
|
|
const countryNames = useCountryNames(locale);
|
2023-07-13 17:37:51 +02:00
|
|
|
const { basePath } = useRouter();
|
2023-02-18 06:42:42 +01:00
|
|
|
|
|
|
|
const renderCountryName = useCallback(
|
2023-07-13 17:37:51 +02:00
|
|
|
({ x: code }) => (
|
|
|
|
<span className={classNames(locale, styles.row)}>
|
|
|
|
<img src={`${basePath}/images/flags/${code?.toLowerCase() || 'xx'}.png`} alt={code} />
|
|
|
|
{countryNames[code]}
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
[countryNames, locale, basePath],
|
2023-02-18 06:42:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DataTable
|
|
|
|
title={formatMessage(labels.countries)}
|
|
|
|
metric={formatMessage(labels.visitors)}
|
|
|
|
data={data}
|
|
|
|
renderLabel={renderCountryName}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default RealtimeCountries;
|