import dayjs from "@calcom/dayjs"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { inferQueryOutput, trpc } from "@calcom/trpc/react"; import Badge from "@calcom/ui/Badge"; import Button from "@calcom/ui/Button"; import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent"; import { Dialog, DialogTrigger } from "@calcom/ui/Dialog"; import { Icon } from "@calcom/ui/Icon"; import { ListItem } from "@calcom/ui/List"; import { Tooltip } from "@calcom/ui/Tooltip"; export type TApiKeys = inferQueryOutput<"viewer.apiKeys.list">[number]; export default function ApiKeyListItem(props: { apiKey: TApiKeys; onEditApiKey: () => void }) { const { t } = useLocale(); const utils = trpc.useContext(); const isExpired = props?.apiKey?.expiresAt ? props.apiKey.expiresAt < new Date() : null; const neverExpires = props?.apiKey?.expiresAt === null; const deleteApiKey = trpc.useMutation("viewer.apiKeys.delete", { async onSuccess() { await utils.invalidateQueries(["viewer.apiKeys.list"]); }, }); return (
{props?.apiKey?.note ? props.apiKey.note : t("api_key_no_note")} {!neverExpires && isExpired && ( {t("expired")} )}
{neverExpires ? (
{t("api_key_never_expires")}
) : ( `${isExpired ? t("expired") : t("expires")} ${dayjs( props?.apiKey?.expiresAt?.toString() ).fromNow()}` )}
); }