insomnia/app/ui/components/editors/AuthEditor.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-11-26 08:29:16 +00:00
import React, {PropTypes, PureComponent} from 'react';
import KeyValueEditor from '../keyvalueeditor/Editor';
import {trackEvent} from '../../../analytics/index';
2016-04-09 21:08:55 +00:00
2016-11-26 08:29:16 +00:00
class AuthEditor extends PureComponent {
_handleOnCreate = () => trackEvent('Auth Editor', 'Create');
_handleOnDelete = () => trackEvent('Auth Editor', 'Delete');
_handleToggleDisable = pair => {
const label = pair.disabled ? 'Disable' : 'Enable';
trackEvent('Auth Editor', 'Toggle', label);
};
_handleChange = pairs => {
const pair = {
username: pairs.length ? pairs[0].name : '',
password: pairs.length ? pairs[0].value : '',
disabled: pairs.length ? pairs[0].disabled : false,
};
this.props.onChange(pair);
};
render () {
const {authentication, showPasswords, handleRender} = this.props;
2016-11-26 08:29:16 +00:00
const pairs = [{
name: authentication.username || '',
value: authentication.password || '',
disabled: authentication.disabled || false,
}];
return (
<KeyValueEditor
pairs={pairs}
maxPairs={1}
handleRender={handleRender}
2016-11-26 08:29:16 +00:00
namePlaceholder="Username"
valuePlaceholder="•••••••••••"
2016-11-26 08:29:16 +00:00
valueInputType={showPasswords ? 'text' : 'password'}
onToggleDisable={this._handleToggleDisable}
onCreate={this._handleOnCreate}
onDelete={this._handleOnDelete}
onChange={this._handleChange}
/>
);
}
}
2016-04-09 21:08:55 +00:00
AuthEditor.propTypes = {
handleRender: PropTypes.func.isRequired,
2016-11-26 00:37:59 +00:00
handleUpdateSettingsShowPasswords: PropTypes.func.isRequired,
2016-04-09 21:08:55 +00:00
onChange: PropTypes.func.isRequired,
2016-11-26 00:37:59 +00:00
authentication: PropTypes.object.isRequired,
showPasswords: PropTypes.bool.isRequired,
2016-04-09 21:08:55 +00:00
};
export default AuthEditor;