2020-08-09 12:04:48 +02:00
|
|
|
import React, { useState } from 'react';
|
2022-02-23 07:47:59 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-09-17 06:55:32 +02:00
|
|
|
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';
|
2022-02-23 07:47:59 +01:00
|
|
|
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
|
|
|
|
2020-09-17 06:55:32 +02:00
|
|
|
const WEBSITES = '/settings';
|
|
|
|
const ACCOUNTS = '/settings/accounts';
|
|
|
|
const PROFILE = '/settings/profile';
|
2020-08-07 08:02:24 +02:00
|
|
|
|
2020-08-09 08:48:43 +02:00
|
|
|
export default function Settings() {
|
2022-02-23 07:47:59 +01:00
|
|
|
const { user } = useUser();
|
2020-09-06 02:27:01 +02:00
|
|
|
const [option, setOption] = useState(WEBSITES);
|
2020-09-17 06:55:32 +02:00
|
|
|
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 06:55:32 +02:00
|
|
|
{
|
2020-09-17 07:29:40 +02:00
|
|
|
label: <FormattedMessage id="label.profile" defaultMessage="Profile" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
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}>
|
2020-09-17 06:55:32 +02:00
|
|
|
{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
|
|
|
);
|
|
|
|
}
|