/* @flow */
import React from 'react';
import Flux from '../../lib/flux';
import FormSection from '../../uikit/form/FormSection';
import FormText, {Types as FormTextTypes} from '../../uikit/form/FormText';
import Button, {ButtonLooks, ButtonColors} from '../../uikit/Button';
import GuildSettingsStore from '../../stores/GuildSettingsStore';
import UserStore from '../../stores/UserStore';
import UserSettingsModalActionCreators from '../../actions/UserSettingsModalActionCreators';
import GuildSettingsActionCreators from '../../actions/GuildSettingsActionCreators';
import i18n from '../../i18n';
import type UserRecord from '../../records/UserRecord';
import type GuildRecord from '../../records/GuildRecord';
import {MFALevels, UserSettingsSections} from '../../Constants';
type Props = {
currentUser: UserRecord,
guild: GuildRecord,
mfaLevel: number,
};
class MFASettings extends React.PureComponent {
props: Props;
constructor(props) {
super(props);
(this: any).setMFAEnabled = this.setMFAEnabled.bind(this);
(this: any).handleEnableMFA = this.handleEnableMFA.bind(this);
(this: any).handleDisableMFA = this.handleDisableMFA.bind(this);
}
renderEnableButton() {
const {currentUser, guild} = this.props;
const canChangeMFALevel = currentUser.mfaEnabled && guild.isOwnerWithRequiredMfaLevel(currentUser);
return (
);
}
renderDisableButton() {
const {currentUser, guild} = this.props;
const canChangeMFALevel = currentUser.mfaEnabled && guild.isOwnerWithRequiredMfaLevel(currentUser);
return (
);
}
render() {
const {currentUser, mfaLevel} = this.props;
return (
{i18n.Messages.GUILD_SECURITY_REQ_MFA_BODY.format()}
{' '}
{!currentUser.mfaEnabled
? i18n.Messages.GUILD_SECURITY_REQ_MFA_ENABLE.format({onClick: this.openUserAccountModal})
: null}
{mfaLevel === MFALevels.ELEVATED ? this.renderDisableButton() : this.renderEnableButton()}
);
}
setMFAEnabled(enable: boolean) {
const {guild} = this.props;
GuildSettingsActionCreators.updateMFALevel({
guildId: guild.id,
level: enable ? MFALevels.ELEVATED : MFALevels.NONE,
isEnabled: !enable,
});
}
handleEnableMFA() {
this.setMFAEnabled(true);
}
handleDisableMFA() {
this.setMFAEnabled(false);
}
openUserAccountModal() {
UserSettingsModalActionCreators.open(UserSettingsSections.ACCOUNT);
}
}
export default Flux.connectStores([UserStore, GuildSettingsStore], () => {
const {mfaLevel, guild} = GuildSettingsStore.getProps();
return {
currentUser: UserStore.getCurrentUser(),
mfaLevel,
guild,
};
})(MFASettings);
// WEBPACK FOOTER //
// ./discord_app/components/guild_settings/MFASettings.js