import { useQuery } from "@tanstack/react-query"; import { HiEllipsisHorizontal } from "react-icons/hi2"; import { twMerge } from "tailwind-merge"; import { authClient } from "@kan/auth/client"; import Dropdown from "~/components/Dropdown"; import { useModal } from "~/providers/modal"; export default function ApiKeyList() { const { openModal } = useModal(); const { data, isLoading } = useQuery({ queryKey: ["apiKeys"], queryFn: () => authClient.apiKey.list(), }); const TableRow = ({ keyId, keyName, keyStart, createdAt, lastRequest, isLastRow, showSkeleton, }: { keyId?: string; keyName?: string | null | undefined; keyStart?: string | null | undefined; createdAt?: Date | null; lastRequest?: Date | null; isLastRow?: boolean | undefined; showSkeleton?: boolean | undefined; }) => { const formatDate = (date?: Date | string | null) => { if (!date) return "Never"; const dateObj = date instanceof Date ? date : new Date(date); return dateObj.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", }); }; return (

{keyName}

{formatDate(createdAt)}

{formatDate(lastRequest)}

{keyStart}...
openModal("REVOKE_API_KEY", keyId, keyName ?? ""), }, ]} >
); }; if (!isLoading && (!data?.data || data.data.length === 0)) { return null; } return (
{!isLoading && data?.data?.map((apiKey, index) => ( ))} {isLoading && ( <> )}
Name Created Last Used Key {/* Actions column */}
); }