File size: 1,842 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import { Button, Dialog, Gridicon } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import { recordGoogleEvent } from '../../state/analytics/actions';
import { successNotice } from '../../state/notices/actions';
class Security2faKeyDeleteButton extends Component {
static propTypes = {
securityKey: PropTypes.object.isRequired,
};
state = {
showDialog: false,
};
buttons = {};
handleRemoveKeyButtonClick = () => {
this.buttons = [
{ action: 'cancel', label: this.props.translate( 'Cancel' ) },
{
action: 'delete',
label: this.props.translate( 'Remove key' ),
onClick: this.onDeleteKey,
additionalClassNames: 'is-scary',
},
];
this.setState( { showDialog: ! this.state.showDialog } );
};
onCloseDialog = () => {
this.setState( { showDialog: false } );
};
onDeleteKey = ( closeDialog ) => {
// Actually delete the key
if ( this.props.onDelete ) {
this.props.onDelete( this.props.securityKey );
}
// Close the dialog
closeDialog();
};
render() {
return (
<Fragment>
<Button
compact
className="security-2fa-key__delete-key"
onClick={ this.handleRemoveKeyButtonClick }
>
<Gridicon icon="trash" />
</Button>
{ this.state.showDialog && (
<Dialog
isVisible={ this.state.showDialog }
buttons={ this.buttons }
onClose={ this.onCloseDialog }
>
<h1>{ this.props.translate( 'Remove key?' ) }</h1>
<p>{ this.props.translate( 'Are you sure you want to remove this security key?' ) }</p>
</Dialog>
) }
</Fragment>
);
}
}
export default connect(
null,
{
successNotice,
recordGoogleEvent,
},
null
)( localize( Security2faKeyDeleteButton ) );
|