umami/components/layout/Header.js

60 lines
2.2 KiB
JavaScript
Raw Normal View History

import Logo from 'assets/logo.svg';
import HamburgerButton from 'components/common/HamburgerButton';
2020-08-08 05:36:57 +02:00
import Link from 'components/common/Link';
import UpdateNotice from 'components/common/UpdateNotice';
2020-09-20 10:33:39 +02:00
import LanguageButton from 'components/settings/LanguageButton';
import ThemeButton from 'components/settings/ThemeButton';
2020-09-21 06:31:53 +02:00
import UserButton from 'components/settings/UserButton';
2022-08-29 05:20:54 +02:00
import useConfig from 'hooks/useConfig';
2022-08-09 23:58:27 +02:00
import useUser from 'hooks/useUser';
import { HOMEPAGE_URL } from 'lib/constants';
import { useRouter } from 'next/router';
import { Column, Icon, Row } from 'react-basics';
import { FormattedMessage } from 'react-intl';
2022-11-10 13:47:02 +01:00
import SettingsButton from '../settings/SettingsButton';
import styles from './Header.module.css';
2020-07-24 04:56:55 +02:00
2022-10-13 01:29:44 +02:00
export default function Header() {
const user = useUser();
const { pathname } = useRouter();
2022-10-28 01:42:57 +02:00
const { updatesDisabled, adminDisabled } = useConfig();
2022-08-09 23:58:27 +02:00
const isSharePage = pathname.includes('/share/');
const allowUpdate = user?.isAdmin && !updatesDisabled && !isSharePage;
2020-08-05 07:45:05 +02:00
2020-07-24 04:56:55 +02:00
return (
2022-03-01 03:39:37 +01:00
<>
2022-08-09 23:58:27 +02:00
{allowUpdate && <UpdateNotice />}
2022-12-10 23:26:52 +01:00
<header className={styles.header}>
<Row>
<Column className={styles.title}>
<Icon size="lg" className={styles.logo}>
<Logo />
</Icon>
2022-12-10 23:26:52 +01:00
<Link href={isSharePage ? HOMEPAGE_URL : '/'}>umami</Link>
</Column>
<HamburgerButton />
{user && !adminDisabled && (
<div className={styles.links}>
<Link href="/dashboard">
<FormattedMessage id="label.dashboard" defaultMessage="Dashboard" />
</Link>
<Link href="/realtime">
<FormattedMessage id="label.realtime" defaultMessage="Realtime" />
</Link>
<Link href="/websites">
2022-12-10 23:26:52 +01:00
<FormattedMessage id="label.settings" defaultMessage="Settings" />
</Link>
</div>
)}
<Column className={styles.buttons}>
<ThemeButton />
<LanguageButton menuAlign="right" />
<SettingsButton />
{user && !adminDisabled && <UserButton />}
</Column>
</Row>
2022-03-01 03:39:37 +01:00
</header>
</>
2020-07-24 04:56:55 +02:00
);
}