import PropTypes from 'prop-types'; import React from 'react'; import format from 'date-fns/format'; import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; import orderBy from 'lodash/orderBy'; import { APIKeyPropType } from './APIKeyForm'; import TrashCanIcon from '../../../images/trash-can.svg'; function APIKeyList({ apiKeys, onRemove, t }) { return ( {orderBy(apiKeys, ['createdAt'], ['desc']).map((key) => { const lastUsed = key.lastUsedAt ? distanceInWordsToNow(new Date(key.lastUsedAt), { addSuffix: true }) : t('APIKeyList.Never'); return ( ); })}
{t('APIKeyList.Name')} {t('APIKeyList.Created')} {t('APIKeyList.LastUsed')} {t('APIKeyList.Actions')}
{key.label} {format(new Date(key.createdAt), 'MMM D, YYYY h:mm A')} {lastUsed}
); } APIKeyList.propTypes = { apiKeys: PropTypes.arrayOf(PropTypes.shape(APIKeyPropType)).isRequired, onRemove: PropTypes.func.isRequired, t: PropTypes.func.isRequired }; export default APIKeyList;