import * as React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useDispatch } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { fetchMfa } from 'soapbox/actions/mfa'; import { useAppSelector, useOwnAccount } from 'soapbox/hooks'; import List, { ListItem } from '../../components/list'; import { Button, Card, CardBody, CardHeader, CardTitle, Column } from '../../components/ui'; 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' }, deleteAccount: { id: 'settings.delete_account', defaultMessage: 'Delete Account' }, }); /** User settings page. */ const Settings = () => { const dispatch = useDispatch(); const history = useHistory(); const intl = useIntl(); const mfa = useAppSelector((state) => state.security.get('mfa')); const account = useOwnAccount(); const navigateToChangeEmail = React.useCallback(() => history.push('/settings/email'), [history]); const navigateToChangePassword = React.useCallback(() => history.push('/settings/password'), [history]); const navigateToMfa = React.useCallback(() => history.push('/settings/mfa'), [history]); const navigateToEditProfile = React.useCallback(() => history.push('/settings/profile'), [history]); const isMfaEnabled = mfa.getIn(['settings', 'totp']); React.useEffect(() => { dispatch(fetchMfa()); }, [dispatch]); if (!account) return null; const displayName = account.display_name || account.username; return ( {displayName} {isMfaEnabled ? intl.formatMessage({ id: 'mfa.enabled', defaultMessage: 'Enabled' }) : intl.formatMessage({ id: 'mfa.disabled', defaultMessage: 'Disabled' })}
); }; export default Settings;