import { ActionIcon, Group, Menu, Table, Text } from "@mantine/core"; import { IconDots, IconEdit, IconTrash } from "@tabler/icons-react"; import { format } from "date-fns"; import { useTranslation } from "react-i18next"; import { IApiKey } from "@/ee/api-key"; import { CustomAvatar } from "@/components/ui/custom-avatar.tsx"; import React from "react"; import NoTableResults from "@/components/common/no-table-results"; interface ApiKeyTableProps { apiKeys: IApiKey[]; isLoading?: boolean; showUserColumn?: boolean; onUpdate?: (apiKey: IApiKey) => void; onRevoke?: (apiKey: IApiKey) => void; } export function ApiKeyTable({ apiKeys, isLoading, showUserColumn = false, onUpdate, onRevoke, }: ApiKeyTableProps) { const { t } = useTranslation(); const formatDate = (date: Date | string | null) => { if (!date) return t("Never"); return format(new Date(date), "MMM dd, yyyy"); }; const isExpired = (expiresAt: string | null) => { if (!expiresAt) return false; return new Date(expiresAt) < new Date(); }; return ( {t("Name")} {showUserColumn && {t("User")}} {t("Last used")} {t("Expires")} {t("Created")} {apiKeys && apiKeys.length > 0 ? ( apiKeys.map((apiKey: IApiKey, index: number) => ( {apiKey.name} {showUserColumn && apiKey.creator && ( {apiKey.creator.name} )} {formatDate(apiKey.lastUsedAt)} {apiKey.expiresAt ? ( isExpired(apiKey.expiresAt) ? ( {t("Expired")} ) : ( {formatDate(apiKey.expiresAt)} ) ) : ( {t("Never")} )} {formatDate(apiKey.createdAt)} {onUpdate && ( } onClick={() => onUpdate(apiKey)} > {t("Rename")} )} {onRevoke && ( } color="red" onClick={() => onRevoke(apiKey)} > {t("Revoke")} )} )) ) : ( )}
); }