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

42 lines
1.2 KiB
JavaScript
Raw Normal View History

import React, {PropTypes} from 'react';
import KeyValueEditor from '../base/KeyValueEditor';
import {trackEvent} from '../../../analytics/index';
2016-04-09 21:08:55 +00:00
const AuthEditor = ({request, showPasswords, onChange, ...other}) => {
2016-04-29 04:57:03 +00:00
const auth = request.authentication;
const pairs = [{
name: auth.username || '',
value: auth.password || '',
disabled: auth.disabled || false,
2016-04-29 04:57:03 +00:00
}];
2016-04-09 21:08:55 +00:00
2016-04-29 04:57:03 +00:00
return (
<KeyValueEditor
pairs={pairs}
maxPairs={1}
namePlaceholder="Username"
valuePlaceholder="********"
valueInputType={showPasswords ? 'text' : 'password'}
onToggleDisable={pair => trackEvent('Auth Editor', 'Toggle', pair.disabled ? 'Disable' : 'Enable')}
onCreate={() => trackEvent('Auth Editor', 'Create')}
onDelete={() => trackEvent('Auth Editor', 'Delete')}
2016-04-29 04:57:03 +00:00
onChange={pairs => onChange({
username: pairs.length ? pairs[0].name : '',
password: pairs.length ? pairs[0].value : '',
disabled: pairs.length ? pairs[0].disabled : false,
})}
2016-04-29 04:57:03 +00:00
{...other}
/>
);
2016-05-01 20:46:11 +00:00
};
2016-04-09 21:08:55 +00:00
AuthEditor.propTypes = {
2016-04-09 21:08:55 +00:00
onChange: PropTypes.func.isRequired,
request: PropTypes.shape({
authentication: PropTypes.object.isRequired
}),
showPasswords: PropTypes.bool.isRequired
2016-04-09 21:08:55 +00:00
};
export default AuthEditor;