File size: 1,874 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
import { Button, FormLabel } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import FormButton from 'calypso/components/forms/form-button';
import FormFieldset from 'calypso/components/forms/form-fieldset';
import FormTextInput from 'calypso/components/forms/form-text-input';

class Security2faKeyAddName extends Component {
	static propTypes = {
		onNameSubmit: PropTypes.func.isRequired,
		onCancel: PropTypes.func.isRequired,
	};

	state = {
		keyName: '',
	};

	componentDidMount = () => {
		this.keyNameInput.focus();
	};

	submitName = ( e ) => {
		e.preventDefault();
		this.props.onNameSubmit( this.state.keyName );
	};

	handleChange = ( e ) => {
		const { value } = e.currentTarget;
		this.setState( { keyName: value } );
	};

	render() {
		return (
			<form className="security-2fa-key__add-key-name-form" onSubmit={ this.submitName }>
				<FormFieldset>
					<FormLabel htmlFor="security-2fa-key__key-name">
						{ this.props.translate(
							'Give the security key a name. Make it up! It can be anything.'
						) }
					</FormLabel>
					<FormTextInput
						autoComplete="off"
						className="security-2fa-key__key-name"
						id="security-2fa-key__key_name"
						name="security_key_name"
						ref={ ( input ) => ( this.keyNameInput = input ) }
						placeholder={ this.props.translate( 'My Android phone' ) }
						onChange={ this.handleChange }
						value={ this.state.keyName }
					/>
				</FormFieldset>
				<FormButton
					className="security-2fa-key__register-key"
					disabled={ 0 === this.state.keyName.length }
				>
					{ this.props.translate( 'Register key' ) }
				</FormButton>
				<Button onClick={ this.props.onCancel }>{ this.props.translate( 'Cancel' ) }</Button>
			</form>
		);
	}
}

export default localize( Security2faKeyAddName );