import { faKey, faXmark } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { format } from "date-fns"; import { createNotification } from "@app/components/notifications"; import { EmptyState, IconButton, Table, TableContainer, TableSkeleton, TBody, Td, Th, THead, Tr } from "@app/components/v2"; import { useDeleteAPIKey, useGetMyAPIKeys } from "@app/hooks/api"; export const APIKeyTable = () => { const { data, isLoading } = useGetMyAPIKeys(); const { mutateAsync } = useDeleteAPIKey(); const handleDeleteAPIKeyDataClick = async (apiKeyDataId: string) => { try { await mutateAsync(apiKeyDataId); createNotification({ text: "Successfully deleted API key", type: "success" }); } catch (err) { console.error(err); createNotification({ text: "Failed to delete API key", type: "error" }); } }; return ( {isLoading && } {!isLoading && data && data.length > 0 && data.map(({ id, name, createdAt, expiresAt, lastUsed }) => { return ( ); })} {!isLoading && data && data?.length === 0 && ( )}
Name Last active Created Expiration
{name} {format(new Date(lastUsed), "yyyy-MM-dd")} {format(new Date(createdAt), "yyyy-MM-dd")} {format(new Date(expiresAt), "yyyy-MM-dd")} { await handleDeleteAPIKeyDataClick(id); }} size="lg" colorSchema="danger" variant="plain" ariaLabel="update" >
); };