fc4075b372
* Add query to get api keys * Add a link to apiKey detail page * Reset generatedApiKey when leaving page * Simplify stuff * Regenerate key when clicking on button * Simplify * Fix test * Refetch apiKeys when delete or create one * Add test for utils * Create utils function * Enable null expiration dates * Update formatExpiration * Fix display * Fix noteCard * Fix errors * Fix reset * Fix display * Fix renaming * Fix tests * Fix ci * Fix mocked data * Fix test * Update coverage requiremeents * Rename folder * Code review returns * Symplify sht code
32 lines
903 B
TypeScript
32 lines
903 B
TypeScript
import { ApiFieldItem } from '@/settings/developers/types/ApiFieldItem';
|
|
import { GetApiKeysQuery } from '~/generated/graphql';
|
|
import { beautifyDateDiff } from '~/utils/date-utils';
|
|
|
|
export const formatExpiration = (
|
|
expiresAt: string | null,
|
|
withExpiresMention: boolean = false,
|
|
short: boolean = true,
|
|
) => {
|
|
if (expiresAt) {
|
|
const dateDiff = beautifyDateDiff(expiresAt, undefined, short);
|
|
if (dateDiff.includes('-')) {
|
|
return 'Expired';
|
|
}
|
|
return withExpiresMention ? `Expires in ${dateDiff}` : `In ${dateDiff}`;
|
|
}
|
|
return withExpiresMention ? 'Never expires' : 'Never';
|
|
};
|
|
|
|
export const formatExpirations = (
|
|
apiKeysQuery: GetApiKeysQuery,
|
|
): ApiFieldItem[] => {
|
|
return apiKeysQuery.findManyApiKey.map(({ id, name, expiresAt }) => {
|
|
return {
|
|
id,
|
|
name,
|
|
expiration: formatExpiration(expiresAt || null),
|
|
type: 'internal',
|
|
};
|
|
});
|
|
};
|