mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Added useFormat hook to format special values.
This commit is contained in:
parent
a71cf675ae
commit
2eee9c23c3
9 changed files with 68 additions and 19 deletions
39
hooks/useFormat.js
Normal file
39
hooks/useFormat.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import useMessages from './useMessages';
|
||||
import { BROWSERS } from 'lib/constants';
|
||||
import useLocale from './useLocale';
|
||||
import useCountryNames from './useCountryNames';
|
||||
|
||||
export function useFormat() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { locale } = useLocale();
|
||||
const countryNames = useCountryNames(locale);
|
||||
|
||||
const formatBrowser = value => {
|
||||
return BROWSERS[value] || value;
|
||||
};
|
||||
|
||||
const formatCountry = value => {
|
||||
return countryNames[value] || value;
|
||||
};
|
||||
|
||||
const formatDevice = value => {
|
||||
return formatMessage(labels[value] || labels.unknown);
|
||||
};
|
||||
|
||||
const formatValue = (value, type) => {
|
||||
switch (type) {
|
||||
case 'browser':
|
||||
return formatBrowser(value);
|
||||
case 'country':
|
||||
return formatCountry(value);
|
||||
case 'device':
|
||||
return formatDevice(value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
return { formatBrowser, formatCountry, formatDevice, formatValue };
|
||||
}
|
||||
|
||||
export default useFormat;
|
||||
Loading…
Add table
Add a link
Reference in a new issue