umami/components/pages/Settings.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-08-09 12:04:48 +02:00
import React, { useState } from 'react';
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';
2020-09-27 09:51:29 +02:00
import WebsiteSettings from '../settings/WebsiteSettings';
import AccountSettings from '../settings/AccountSettings';
import ProfileSettings from '../settings/ProfileSettings';
2020-08-09 11:03:37 +02:00
import { useSelector } from 'react-redux';
2020-09-06 02:27:01 +02:00
import { FormattedMessage } from 'react-intl';
const WEBSITES = '/settings';
const ACCOUNTS = '/settings/accounts';
const PROFILE = '/settings/profile';
2020-08-09 08:48:43 +02:00
export default function Settings() {
2020-08-09 11:03:37 +02:00
const user = useSelector(state => state.user);
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
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
);
}