2018-10-13 20:14:46 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
class APIKeyForm extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = { keyLabel: '' };
|
|
|
|
|
|
|
|
this.addKey = this.addKey.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
addKey(event) {
|
|
|
|
event.preventDefault();
|
2018-10-15 22:22:56 +00:00
|
|
|
document.getElementById('addKeyForm').reset();
|
|
|
|
this.props.addApiKey(this.state.keyLabel);
|
2018-10-13 20:14:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:22:56 +00:00
|
|
|
removeKey(keyId) {
|
|
|
|
this.props.removeApiKey(keyId);
|
2018-10-13 20:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2 className="form__label">Key label</h2>
|
2018-10-15 22:22:56 +00:00
|
|
|
<form id="addKeyForm" className="form" onSubmit={this.addKey}>
|
2018-10-13 20:14:46 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="form__input"
|
2018-10-15 22:22:56 +00:00
|
|
|
placeholder="A name you will be able to recognize"
|
2018-10-13 20:14:46 +00:00
|
|
|
id="keyLabel"
|
|
|
|
onChange={(event) => { this.setState({ keyLabel: event.target.value }); }}
|
|
|
|
/><br />
|
|
|
|
<input
|
|
|
|
type="submit"
|
|
|
|
value="Create new Key"
|
|
|
|
disabled={this.state.keyLabel === ''}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<table className="form__table">
|
|
|
|
<tbody>
|
2018-10-15 22:22:56 +00:00
|
|
|
{this.props.apiKeys && this.props.apiKeys.map(v => (
|
2018-10-13 20:14:46 +00:00
|
|
|
<tr key={v.id}>
|
2018-10-15 22:22:56 +00:00
|
|
|
<td><b>{v.label}</b><br />Created on: {v.createdAt}</td>
|
|
|
|
<td>Last used on:<br /> {v.lastUsedAt}</td>
|
|
|
|
<td><button className="form__button-remove" onClick={() => this.removeKey(v.id)}>Delete</button></td>
|
2018-10-13 20:14:46 +00:00
|
|
|
</tr>))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
APIKeyForm.propTypes = {
|
2018-10-15 22:22:56 +00:00
|
|
|
addApiKey: PropTypes.func.isRequired,
|
|
|
|
removeApiKey: PropTypes.func.isRequired,
|
|
|
|
apiKeys: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.object.isRequired,
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
createdAt: PropTypes.object.isRequired,
|
|
|
|
lastUsedAt: PropTypes.object.isRequired,
|
|
|
|
})).isRequired
|
2018-10-13 20:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default APIKeyForm;
|