insomnia/app/ui/components/editors/auth/bearer-auth.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, {PropTypes, PureComponent} from 'react';
import autobind from 'autobind-decorator';
import OneLineEditor from '../../codemirror/one-line-editor';
import * as misc from '../../../../common/misc';
@autobind
class BearerAuth extends PureComponent {
constructor (props) {
super(props);
this._handleChangeProperty = misc.debounce(this._handleChangeProperty, 500);
}
2017-06-01 13:32:55 +00:00
_handleChange (token) {
const {request} = this.props;
2017-06-01 13:32:55 +00:00
const authentication = Object.assign({}, request.authentication, {token});
this.props.onChange(authentication);
}
render () {
2017-06-01 13:32:55 +00:00
const {request, handleRender, handleGetRenderContext} = this.props;
const {token} = request.authentication;
return (
2017-06-01 13:32:55 +00:00
<div className="form-control form-control--underlined pad no-margin">
<OneLineEditor
className="no-margin"
onChange={this._handleChange}
defaultValue={token || ''}
render={handleRender}
placeholder="token"
getRenderContext={handleGetRenderContext}
/>
</div>
);
}
}
BearerAuth.propTypes = {
handleRender: PropTypes.func.isRequired,
handleGetRenderContext: PropTypes.func.isRequired,
request: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired
};
export default BearerAuth;