umami/components/pages/Settings.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-08-09 12:04:48 +02:00
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { useRouter } from 'next/router';
2020-08-09 08:48:43 +02:00
import Page from 'components/layout/Page';
import MenuLayout from 'components/layout/MenuLayout';
import WebsiteSettings from 'components/settings/WebsiteSettings';
import AccountSettings from 'components/settings/AccountSettings';
import ProfileSettings from 'components/settings/ProfileSettings';
import useUser from 'hooks/useUser';
2020-09-06 02:27:01 +02:00
const WEBSITES = '/settings';
const ACCOUNTS = '/settings/accounts';
const PROFILE = '/settings/profile';
2020-08-09 08:48:43 +02:00
export default function Settings() {
const { user } = useUser();
2020-09-06 02:27:01 +02:00
const [option, setOption] = useState(WEBSITES);
const router = useRouter();
const { pathname } = router;
2020-08-09 11:03:37 +02:00
2022-02-27 00:53:45 +01:00
if (!user) {
return null;
}
2020-08-10 00:13:38 +02:00
const menuOptions = [
2020-09-06 02:27:01 +02:00
{
2020-09-17 07:29:40 +02:00
label: <FormattedMessage id="label.websites" defaultMessage="Websites" />,
2020-09-06 02:27:01 +02:00
value: WEBSITES,
},
{
2020-09-17 07:29:40 +02:00
label: <FormattedMessage id="label.accounts" defaultMessage="Accounts" />,
2020-09-06 02:27:01 +02:00
value: ACCOUNTS,
2020-09-30 06:22:08 +02:00
hidden: !user?.is_admin,
2020-09-06 02:27:01 +02:00
},
{
2020-09-17 07:29:40 +02:00
label: <FormattedMessage id="label.profile" defaultMessage="Profile" />,
value: PROFILE,
},
2020-08-10 00:13:38 +02:00
];
2020-08-09 11:03:37 +02:00
2020-08-05 07:45:05 +02:00
return (
2020-08-06 04:04:02 +02:00
<Page>
2020-08-09 12:04:48 +02:00
<MenuLayout menu={menuOptions} selectedOption={option} onMenuSelect={setOption}>
{pathname === WEBSITES && <WebsiteSettings />}
{pathname === ACCOUNTS && <AccountSettings />}
{pathname === PROFILE && <ProfileSettings />}
2020-08-09 08:48:43 +02:00
</MenuLayout>
2020-08-06 04:04:02 +02:00
</Page>
2020-08-05 07:45:05 +02:00
);
}