lastUserAt should be null if the key has never been used

This commit is contained in:
Andrew Nicolaou 2019-05-15 12:28:18 +02:00 committed by Cassie Tarakajian
parent 3e760ca0b8
commit 89dd41d81f
3 changed files with 6 additions and 5 deletions

View file

@ -10,9 +10,10 @@ const plusIcon = require('../../../images/plus-icon.svg');
export const APIKeyPropType = PropTypes.shape({
id: PropTypes.object.isRequired,
token: PropTypes.object,
label: PropTypes.string.isRequired,
createdAt: PropTypes.object.isRequired,
lastUsedAt: PropTypes.object.isRequired,
createdAt: PropTypes.string.isRequired,
lastUsedAt: PropTypes.string,
});
class APIKeyForm extends React.Component {

View file

@ -22,13 +22,13 @@ function APIKeyList({ apiKeys, onRemove }) {
</thead>
<tbody>
{orderBy(apiKeys, ['createdAt'], ['desc']).map((key) => {
const hasNewToken = !!key.token;
const lastUsed = key.lastUsedAt ? distanceInWordsToNow(new Date(key.lastUsedAt), { addSuffix: true }) : 'Never';
return (
<tr key={key.id}>
<td>{key.label}</td>
<td>{format(new Date(key.createdAt), 'MMM D, YYYY h:mm A')}</td>
<td>{distanceInWordsToNow(new Date(key.lastUsedAt), { addSuffix: true })}</td>
<td>{lastUsed}</td>
<td className="api-key-list__action">
<button className="api-key-list__delete-button" onClick={() => onRemove(key)}>
<InlineSVG src={trashCan} alt="Delete Key" />

View file

@ -12,7 +12,7 @@ const { Schema } = mongoose;
const apiKeySchema = new Schema({
label: { type: String, default: 'API Key' },
lastUsedAt: { type: Date, required: true, default: Date.now },
lastUsedAt: { type: Date },
hashedKey: { type: String, required: true },
}, { timestamps: true, _id: true });