import PropTypes from 'prop-types'; import React from 'react'; import InlineSVG from 'react-inlinesvg'; import format from 'date-fns/format'; import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; import orderBy from 'lodash/orderBy'; const trashCan = require('../../../images/trash-can.svg'); function NewTokenDisplay({ token }) { return (

Make sure to copy your new personal access token now. You won’t be able to see it again!

); } function TokenMetadataList({ tokens, onRemove }) { return ( {orderBy(tokens, ['createdAt'], ['desc']).map((v) => { const keyRow = ( ); const newKeyValue = v.token && ( ); return [keyRow, newKeyValue]; })}
Name Created on Last used Actions
{v.label} {format(new Date(v.createdAt), 'MMM D, YYYY h:mm A')} {distanceInWordsToNow(new Date(v.lastUsedAt), { addSuffix: true })}
); } class APIKeyForm extends React.Component { constructor(props) { super(props); this.state = { keyLabel: '' }; this.addKey = this.addKey.bind(this); this.removeKey = this.removeKey.bind(this); this.renderApiKeys = this.renderApiKeys.bind(this); } addKey(event) { event.preventDefault(); const { keyLabel } = this.state; this.setState({ keyLabel: '' }); this.props.createApiKey(keyLabel); return false; } removeKey(key) { const message = `Are you sure you want to delete "${key.label}"?`; if (window.confirm(message)) { this.props.removeApiKey(key.id); } } renderApiKeys() { const hasApiKeys = this.props.apiKeys && this.props.apiKeys.length > 0; if (hasApiKeys) { return ( ); } return

You have no API keys

; } render() { return (
{ this.setState({ keyLabel: event.target.value }); }} />
{this.renderApiKeys()}
); } } 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;