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(); document.getElementById('addKeyForm').reset(); this.props.createApiKey(this.state.keyLabel) .then(newToken => this.setState({ newToken })); this.state.keyLabel = ''; return false; } removeKey(keyId) { this.props.removeApiKey(keyId); } render() { const { newToken } = this.state; const content = newToken ? (

Here is your new key. Copy it somewhere, you won't be able to see it later !

) : (

Key label

{ this.setState({ keyLabel: event.target.value }); }} />
); return (
{content} {this.props.apiKeys && this.props.apiKeys.map(v => ( ))}
{v.label}
Created on: {v.createdAt}
Last used on:
{v.lastUsedAt}
); } } APIKeyForm.propTypes = { createApiKey: 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 }; export default APIKeyForm;