import { Card } from '@automattic/components';
import { localizeUrl } from '@automattic/i18n-utils';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import FormButton from 'calypso/components/forms/form-button';
import FormSectionHeading from 'calypso/components/forms/form-section-heading';
import InlineSupportLink from 'calypso/components/inline-support-link';
import Security2faCodePrompt from 'calypso/me/security-2fa-code-prompt';
import Security2faStatus from 'calypso/me/security-2fa-status';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import { successNotice } from 'calypso/state/notices/actions';
import getUserSettings from 'calypso/state/selectors/get-user-settings';
import './style.scss';
class Security2faDisable extends Component {
static propTypes = {
onFinished: PropTypes.func.isRequired,
userSettings: PropTypes.object.isRequired,
translate: PropTypes.func,
recordGoogleEvent: PropTypes.func,
successNotice: PropTypes.func,
};
constructor() {
super( ...arguments );
this.state = {
showingCodePrompt: false,
};
}
onRevealCodePrompt = () => {
this.props.recordGoogleEvent( 'Me', 'Clicked On Disable Two-Step Authentication Button' );
this.setState( { showingCodePrompt: true } );
};
onCancelCodePrompt = () => {
this.setState( { showingCodePrompt: false } );
};
onCodePromptSuccess = () => {
const { onFinished, translate } = this.props;
this.setState( { showingCodePrompt: false } );
this.props.successNotice( translate( 'Successfully disabled Two-Step Authentication.' ), {
duration: 4000,
} );
onFinished();
};
renderVerificationCodeMeansMessage() {
const { userSettings, translate } = this.props;
if ( userSettings.two_step_sms_enabled ) {
return (
{ translate(
"You've enabled two-step authentication. " +
'While enabled, logging in to WordPress.com ' +
'requires you to enter a unique passcode, sent via text message, ' +
'in addition to your username and password.'
) }
{ translate(
"You're all set to receive authentication codes at " +
'{{strong}}%(smsNumber)s{{/strong}}. ' +
'Want to switch to a different number? No problem! ' +
"You'll need to disable two-step authentication, " +
'then complete the setup process again on another device.',
{
components: {
strong: ,
},
args: {
smsNumber: userSettings.two_step_sms_phone_number,
},
}
) }
{ translate( "You've enabled two-step authentication on your account — smart move! " + "When you log in to WordPress.com, you'll need to enter your " + 'username and password, as well as a unique passcode generated ' + 'by an app on your mobile device.' ) }
{ translate(
'Switching to a new device? ' +
'{{changephonelink}}Follow these steps{{/changephonelink}} ' +
'to avoid losing access to your account.',
{
components: {
changephonelink: (
{ translate( 'You are about to disable two-step authentication. ' + 'This means we will no longer ask for your authentication ' + 'code when you sign into your {{strong}}%(userlogin)s{{/strong}} account.', { components: { strong: , }, args: { userlogin: userSettings.user_login, }, } ) }
{ translate( 'This will also disable your application passwords, ' + 'though you can access them again if you ever re-enable ' + 'two-step authentication. If you decide to re-enable ' + "two-step authentication, keep in mind you'll need to " + 'generate new backup codes.' ) }
{ translate( 'To verify that you wish to disable two-step authentication, ' + 'enter the verification code from your device or a backup code, ' + 'and click "Disable two-step."' ) }