import { PencilAltIcon, TrashIcon } from "@heroicons/react/outline"; import { ExclamationIcon } from "@heroicons/react/solid"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import Button from "@calcom/ui/Button"; import { Dialog, DialogTrigger } from "@calcom/ui/Dialog"; import { Tooltip } from "@calcom/ui/Tooltip"; import { inferQueryOutput, trpc } from "@lib/trpc"; import { ListItem } from "@components/List"; import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent"; import Badge from "@components/ui/Badge"; dayjs.extend(relativeTime); 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()}` )}
); }