umami/components/layout/SettingsLayout.js

38 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-03-24 18:55:20 +01:00
import { Row, Column } from 'react-basics';
2023-03-24 00:33:10 +01:00
import classNames from 'classnames';
import { useRouter } from 'next/router';
2023-03-23 19:46:49 +01:00
import SideNav from './SideNav';
2023-03-24 00:33:10 +01:00
import useUser from 'hooks/useUser';
import useMessages from 'hooks/useMessages';
import useConfig from 'hooks/useConfig';
import styles from './SettingsLayout.module.css';
2023-03-23 19:46:49 +01:00
export default function SettingsLayout({ children }) {
2023-03-24 00:33:10 +01:00
const { user } = useUser();
const { pathname } = useRouter();
2023-03-23 19:46:49 +01:00
const { formatMessage, labels } = useMessages();
2023-03-24 00:33:10 +01:00
const { cloudMode } = useConfig();
2023-03-23 19:46:49 +01:00
const items = [
2023-03-24 00:33:10 +01:00
{ key: 'websites', label: formatMessage(labels.websites), url: '/settings/websites' },
{ key: 'teams', label: formatMessage(labels.teams), url: '/settings/teams' },
user.isAdmin && { key: 'users', label: formatMessage(labels.users), url: '/settings/users' },
{ key: 'profile', label: formatMessage(labels.profile), url: '/settings/profile' },
].filter(n => n);
const getKey = () => items.find(({ url }) => pathname.startsWith(url))?.key;
2023-03-23 19:46:49 +01:00
return (
2023-03-24 18:55:20 +01:00
<Row className={classNames({ [styles.hideMenu]: cloudMode })}>
{!cloudMode && (
<Column className={styles.menu} defaultSize={12} md={3} lg={2} xl={2}>
2023-03-24 00:33:10 +01:00
<SideNav items={items} shallow={true} selectedKey={getKey()} />
2023-03-24 18:55:20 +01:00
</Column>
)}
<Column className={styles.content} defaultSize={12} md={9} lg={10} xl={10}>
{children}
</Column>
</Row>
2023-03-23 19:46:49 +01:00
);
}