2022-05-17 06:32:27 -07:00
|
|
|
import React, { useEffect } from 'react';
|
2022-03-21 11:09:01 -07:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
2022-05-01 14:21:43 -07:00
|
|
|
import { useDispatch } from 'react-redux';
|
2022-03-22 05:42:26 -07:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
import { fetchMfa } from 'soapbox/actions/mfa';
|
2022-05-12 08:45:40 -07:00
|
|
|
import List, { ListItem } from 'soapbox/components/list';
|
2022-05-17 06:32:27 -07:00
|
|
|
import { Card, CardBody, CardHeader, CardTitle, Column } from 'soapbox/components/ui';
|
2022-05-01 14:21:43 -07:00
|
|
|
import { useAppSelector, useOwnAccount } from 'soapbox/hooks';
|
2022-05-12 08:45:40 -07:00
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
import Preferences from '../preferences';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
settings: { id: 'settings.settings', defaultMessage: 'Settings' },
|
|
|
|
profile: { id: 'settings.profile', defaultMessage: 'Profile' },
|
|
|
|
security: { id: 'settings.security', defaultMessage: 'Security' },
|
|
|
|
preferences: { id: 'settings.preferences', defaultMessage: 'Preferences' },
|
|
|
|
editProfile: { id: 'settings.edit_profile', defaultMessage: 'Edit Profile' },
|
|
|
|
changeEmail: { id: 'settings.change_email', defaultMessage: 'Change Email' },
|
|
|
|
changePassword: { id: 'settings.change_password', defaultMessage: 'Change Password' },
|
|
|
|
configureMfa: { id: 'settings.configure_mfa', defaultMessage: 'Configure MFA' },
|
2022-05-12 08:45:40 -07:00
|
|
|
sessions: { id: 'settings.sessions', defaultMessage: 'Active sessions' },
|
2022-03-21 11:09:01 -07:00
|
|
|
deleteAccount: { id: 'settings.delete_account', defaultMessage: 'Delete Account' },
|
2022-05-17 06:32:27 -07:00
|
|
|
other: { id: 'settings.other', defaultMessage: 'Other options' },
|
2022-05-24 03:24:26 -07:00
|
|
|
mfaEnabled: { id: 'mfa.enabled', defaultMessage: 'Enabled' },
|
|
|
|
mfaDisabled: { id: 'mfa.disabled', defaultMessage: 'Disabled' },
|
2022-03-21 11:09:01 -07:00
|
|
|
});
|
|
|
|
|
2022-05-01 14:21:43 -07:00
|
|
|
/** User settings page. */
|
2022-03-22 05:42:26 -07:00
|
|
|
const Settings = () => {
|
2022-03-21 11:09:01 -07:00
|
|
|
const dispatch = useDispatch();
|
2022-03-22 05:42:26 -07:00
|
|
|
const history = useHistory();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-05-01 14:21:43 -07:00
|
|
|
const mfa = useAppSelector((state) => state.security.get('mfa'));
|
2022-05-12 08:45:40 -07:00
|
|
|
const features = useAppSelector((state) => getFeatures(state.instance));
|
2022-05-01 14:21:43 -07:00
|
|
|
const account = useOwnAccount();
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-05-17 06:32:27 -07:00
|
|
|
const navigateToChangeEmail = () => history.push('/settings/email');
|
|
|
|
const navigateToChangePassword = () => history.push('/settings/password');
|
|
|
|
const navigateToMfa = () => history.push('/settings/mfa');
|
|
|
|
const navigateToSessions = () => history.push('/settings/tokens');
|
|
|
|
const navigateToEditProfile = () => history.push('/settings/profile');
|
|
|
|
const navigateToDeleteAccount = () => history.push('/settings/account');
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
const isMfaEnabled = mfa.getIn(['settings', 'totp']);
|
|
|
|
|
2022-05-17 06:32:27 -07:00
|
|
|
useEffect(() => {
|
2022-03-21 11:09:01 -07:00
|
|
|
dispatch(fetchMfa());
|
|
|
|
}, [dispatch]);
|
|
|
|
|
2022-05-01 14:21:43 -07:00
|
|
|
if (!account) return null;
|
|
|
|
|
|
|
|
const displayName = account.display_name || account.username;
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
return (
|
|
|
|
<Column label={intl.formatMessage(messages.settings)} transparent withHeader={false}>
|
|
|
|
<Card variant='rounded'>
|
|
|
|
<CardHeader>
|
|
|
|
<CardTitle title={intl.formatMessage(messages.profile)} />
|
|
|
|
</CardHeader>
|
|
|
|
|
|
|
|
<CardBody>
|
|
|
|
<List>
|
|
|
|
<ListItem label={intl.formatMessage(messages.editProfile)} onClick={navigateToEditProfile}>
|
|
|
|
<span>{displayName}</span>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
</CardBody>
|
|
|
|
|
|
|
|
<CardHeader>
|
|
|
|
<CardTitle title={intl.formatMessage(messages.security)} />
|
|
|
|
</CardHeader>
|
|
|
|
|
|
|
|
<CardBody>
|
|
|
|
<List>
|
|
|
|
<ListItem label={intl.formatMessage(messages.changeEmail)} onClick={navigateToChangeEmail} />
|
|
|
|
<ListItem label={intl.formatMessage(messages.changePassword)} onClick={navigateToChangePassword} />
|
|
|
|
<ListItem label={intl.formatMessage(messages.configureMfa)} onClick={navigateToMfa}>
|
|
|
|
{isMfaEnabled ?
|
2022-05-24 03:24:26 -07:00
|
|
|
intl.formatMessage(messages.mfaEnabled) :
|
|
|
|
intl.formatMessage(messages.mfaDisabled)}
|
2022-03-21 11:09:01 -07:00
|
|
|
</ListItem>
|
2022-05-12 08:45:40 -07:00
|
|
|
{features.sessionsAPI && (
|
|
|
|
<ListItem label={intl.formatMessage(messages.sessions)} onClick={navigateToSessions} />
|
|
|
|
)}
|
2022-03-21 11:09:01 -07:00
|
|
|
</List>
|
|
|
|
</CardBody>
|
|
|
|
|
2022-05-01 14:21:43 -07:00
|
|
|
<CardHeader>
|
2022-03-21 11:09:01 -07:00
|
|
|
<CardTitle title={intl.formatMessage(messages.preferences)} />
|
|
|
|
</CardHeader>
|
|
|
|
|
|
|
|
<CardBody>
|
|
|
|
<Preferences />
|
|
|
|
</CardBody>
|
|
|
|
|
2022-05-17 06:32:27 -07:00
|
|
|
<CardHeader>
|
|
|
|
<CardTitle title={intl.formatMessage(messages.other)} />
|
|
|
|
</CardHeader>
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<CardBody>
|
2022-05-17 06:32:27 -07:00
|
|
|
<List>
|
|
|
|
<ListItem label={intl.formatMessage(messages.deleteAccount)} onClick={navigateToDeleteAccount} />
|
|
|
|
</List>
|
2022-03-21 11:09:01 -07:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-03-22 05:42:26 -07:00
|
|
|
export default Settings;
|