umami/components/layout/NavBar.js

62 lines
2.4 KiB
JavaScript
Raw Normal View History

import { useState } from 'react';
import { useIntl } from 'react-intl';
2023-01-31 06:44:07 +01:00
import { Icon, Text } from 'react-basics';
import classNames from 'classnames';
2023-01-31 06:44:07 +01:00
import Icons from 'components/icons';
2023-02-04 17:59:52 +01:00
import ThemeButton from 'components/input/ThemeButton';
import LanguageButton from 'components/input/LanguageButton';
import LogoutButton from 'components/input/LogoutButton';
import { labels } from 'components/messages';
2023-01-31 06:44:07 +01:00
import useUser from 'hooks/useUser';
import NavGroup from './NavGroup';
import styles from './NavBar.module.css';
export default function NavBar() {
2023-01-31 06:44:07 +01:00
const { user } = useUser();
const { formatMessage } = useIntl();
const [minimized, setMinimized] = useState(false);
const tooltipPosition = minimized ? 'right' : 'top';
const analytics = [
2023-01-31 06:44:07 +01:00
{ label: formatMessage(labels.dashboard), url: '/dashboard', icon: <Icons.Dashboard /> },
{ label: formatMessage(labels.realtime), url: '/realtime', icon: <Icons.Clock /> },
{ label: formatMessage(labels.queries), url: '/queries', icon: <Icons.Search /> },
];
const settings = [
2023-01-31 06:44:07 +01:00
{ label: formatMessage(labels.websites), url: '/settings/websites', icon: <Icons.Globe /> },
user?.isAdmin && {
label: formatMessage(labels.users),
url: '/settings/users',
icon: <Icons.User />,
},
{ label: formatMessage(labels.teams), url: '/settings/teams', icon: <Icons.Users /> },
{ label: formatMessage(labels.profile), url: '/settings/profile', icon: <Icons.Profile /> },
].filter(n => n);
const handleMinimize = () => setMinimized(state => !state);
return (
<div className={classNames(styles.navbar, { [styles.minimized]: minimized })}>
<div className={styles.header} onClick={handleMinimize}>
<Icon size="lg">
2023-01-31 06:44:07 +01:00
<Icons.Logo />
</Icon>
<Text className={styles.text}>umami</Text>
<Icon size="sm" rotate={minimized ? -90 : 90} className={styles.icon}>
<Icons.ChevronDown />
</Icon>
</div>
<NavGroup title={formatMessage(labels.analytics)} items={analytics} minimized={minimized} />
<NavGroup title={formatMessage(labels.settings)} items={settings} minimized={minimized} />
<div className={styles.footer}>
2023-01-21 02:12:53 +01:00
<div className={styles.buttons}>
<ThemeButton tooltipPosition={tooltipPosition} />
<LanguageButton tooltipPosition={tooltipPosition} />
<LogoutButton tooltipPosition={tooltipPosition} />
2023-01-21 02:12:53 +01:00
</div>
</div>
</div>
);
}