umami/components/layout/NavBar.js

71 lines
2.5 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';
2023-02-28 05:03:04 +01:00
import useConfig from 'hooks/useConfig';
export default function NavBar() {
2023-01-31 06:44:07 +01:00
const { user } = useUser();
2023-02-28 05:03:04 +01:00
const { cloudMode } = useConfig();
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 /> },
];
const settings = [
2023-02-28 05:03:04 +01:00
!cloudMode && {
label: formatMessage(labels.websites),
url: '/settings/websites',
icon: <Icons.Globe />,
},
2023-01-31 06:44:07 +01:00
user?.isAdmin && {
label: formatMessage(labels.users),
url: '/settings/users',
icon: <Icons.User />,
},
2023-02-28 05:03:04 +01:00
!cloudMode && {
label: formatMessage(labels.teams),
url: '/settings/teams',
icon: <Icons.Users />,
},
2023-01-31 06:44:07 +01:00
{ 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} />
2023-02-28 05:03:04 +01:00
{!cloudMode && <LogoutButton tooltipPosition={tooltipPosition} />}
2023-01-21 02:12:53 +01:00
</div>
</div>
</div>
);
}