umami/components/layout/SettingsLayout.js

39 lines
1.3 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 { 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
2023-04-21 17:00:42 +02:00
export 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);
2023-04-12 22:40:19 +02:00
const getKey = () => items.find(({ url }) => pathname === url)?.key;
2023-03-23 19:46:49 +01:00
return (
2023-04-12 22:40:19 +02:00
<Row>
2023-03-24 18:55:20 +01:00
{!cloudMode && (
2023-04-12 22:40:19 +02:00
<Column className={styles.menu} defaultSize={12} md={4} lg={3} 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>
)}
2023-04-12 22:40:19 +02:00
<Column className={styles.content} defaultSize={12} md={8} lg={9} xl={10}>
2023-03-24 18:55:20 +01:00
{children}
</Column>
</Row>
2023-03-23 19:46:49 +01:00
);
}
2023-04-21 17:00:42 +02:00
export default SettingsLayout;