import { Card, Spinner } from '@automattic/components'; import { Button } from '@wordpress/components'; import clsx from 'clsx'; import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component } from 'react'; import { connect } from 'react-redux'; import { recordTracksEventWithClientId as recordTracksEvent } from 'calypso/state/analytics/actions'; import { formUpdate, loginUserWithSecurityKey } from 'calypso/state/login/actions'; import TwoFactorActions from './two-factor-actions'; import './verification-code-form.scss'; import './security-key-form.scss'; class SecurityKeyForm extends Component { static propTypes = { formUpdate: PropTypes.func.isRequired, loginUserWithSecurityKey: PropTypes.func.isRequired, onSuccess: PropTypes.func.isRequired, recordTracksEvent: PropTypes.func.isRequired, switchTwoFactorAuthType: PropTypes.func.isRequired, translate: PropTypes.func.isRequired, showOrDivider: PropTypes.bool, isWoo: PropTypes.bool, }; static defaultProps = { isWoo: false, }; state = { isAuthenticating: false, }; componentDidMount() { this.initiateSecurityKeyAuthentication(); } initiateSecurityKeyAuthentication = () => { const { onSuccess } = this.props; this.setState( { isAuthenticating: true } ); this.props .loginUserWithSecurityKey() .then( () => onSuccess() ) .catch( () => this.setState( { isAuthenticating: false } ) ); }; render() { const { translate, isWoo, switchTwoFactorAuthType } = this.props; return (
{ event.preventDefault(); this.initiateSecurityKeyAuthentication(); } } > { ! this.state.isAuthenticating && (

{ translate( '{{strong}}Use your security key to finish logging in.{{/strong}}', { components: { strong: , }, } ) }

{ translate( 'Insert your hardware security key, or follow the instructions in your browser or phone to log in.' ) }

) } { this.state.isAuthenticating && (

{ translate( 'Waiting for security key' ) }

{ translate( 'Connect and touch your security key to log in, or follow the directions in your browser or pop-up.' ) }

) }
); } } export default connect( null, { formUpdate, loginUserWithSecurityKey, recordTracksEvent, } )( localize( SecurityKeyForm ) );