import { Button, Card } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { Component } from 'react';
import { connect } from 'react-redux';
import { Banner } from 'calypso/components/banner';
import SectionHeader from 'calypso/components/section-header';
import { bumpTwoStepAuthMCStat } from 'calypso/lib/two-step-authorization';
import wp from 'calypso/lib/wp';
import Security2faBackupCodesList from 'calypso/me/security-2fa-backup-codes-list';
import Security2faBackupCodesPrompt from 'calypso/me/security-2fa-backup-codes-prompt';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import getUserSetting from 'calypso/state/selectors/get-user-setting';
import './style.scss';
class Security2faBackupCodes extends Component {
constructor( props ) {
super( props );
const printed = this.props.backupCodesPrinted;
this.state = {
printed,
verified: printed,
showPrompt: ! printed,
backupCodes: [],
generatingCodes: false,
};
}
handleGenerateButtonClick = () => {
this.props.recordGoogleEvent( 'Me', 'Clicked on Generate New Backup Codes Button' );
this.setState( {
generatingCodes: true,
verified: false,
showPrompt: true,
} );
wp.req.post( '/me/two-step/backup-codes/new', ( error, data ) => {
if ( ! error ) {
bumpTwoStepAuthMCStat( 'new-backup-codes-success' );
this.setState( {
backupCodes: data.codes,
generatingCodes: false,
} );
}
} );
};
onNextStep = () => {
this.setState( {
backupCodes: [],
printed: true,
} );
};
onVerified = () => {
this.setState( {
printed: true,
verified: true,
showPrompt: false,
} );
};
renderStatus() {
const { translate } = this.props;
if ( ! this.state.printed ) {
return (
{ this.props.translate( 'Backup codes let you access your account if your phone is lost or stolen, or even just accidentally run through the washing machine!' ) }
{ this.renderStatus() } { this.state.showPrompt &&