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';
|
2022-11-01 07:42:37 +01:00
|
|
|
import UserSettings from 'components/settings/UserSettings';
|
2022-02-23 07:47:59 +01:00
|
|
|
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';
|
2022-11-01 07:42:37 +01:00
|
|
|
const ACCOUNTS = '/settings/users';
|
2020-09-17 06:55:32 +02:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
{
|
2022-11-01 07:42:37 +01:00
|
|
|
label: <FormattedMessage id="label.users" defaultMessage="Users" />,
|
2020-09-06 02:27:01 +02:00
|
|
|
value: ACCOUNTS,
|
2022-10-10 22:42:18 +02:00
|
|
|
hidden: !user?.isAdmin,
|
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 />}
|
2022-11-01 07:42:37 +01:00
|
|
|
{pathname === ACCOUNTS && <UserSettings />}
|
2020-09-17 06:55:32 +02:00
|
|
|
{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
|
|
|
);
|
|
|
|
}
|