2016-07-16 02:06:10 +00:00
|
|
|
import React, {PropTypes} from 'react';
|
2016-08-15 17:04:36 +00:00
|
|
|
import KeyValueEditor from '../base/KeyValueEditor';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-04-09 21:08:55 +00:00
|
|
|
|
2016-11-26 00:37:59 +00:00
|
|
|
const AuthEditor = ({authentication, showPasswords, onChange, ...other}) => {
|
2016-04-29 04:57:03 +00:00
|
|
|
const pairs = [{
|
2016-11-26 00:37:59 +00:00
|
|
|
name: authentication.username || '',
|
|
|
|
value: authentication.password || '',
|
|
|
|
disabled: authentication.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"
|
2016-08-15 17:04:36 +00:00
|
|
|
valuePlaceholder="********"
|
2016-07-19 19:13:51 +00:00
|
|
|
valueInputType={showPasswords ? 'text' : 'password'}
|
2016-11-23 19:33:24 +00:00
|
|
|
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({
|
2016-09-12 20:04:15 +00:00
|
|
|
username: pairs.length ? pairs[0].name : '',
|
2016-11-22 19:42:10 +00:00
|
|
|
password: pairs.length ? pairs[0].value : '',
|
|
|
|
disabled: pairs.length ? pairs[0].disabled : false,
|
2016-09-12 20:04:15 +00:00
|
|
|
})}
|
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
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
AuthEditor.propTypes = {
|
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
|
|
|
};
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
export default AuthEditor;
|