'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { ActionCell, ActionDialog, BadgeCell, DataTable, DataTableColumnHeader, DataTableFacetedFilter, DateCell, SearchToolbarItem, TextCell, standardFilterFn } from "@hexclave/ui"; import { ColumnDef, Row, Table } from "@tanstack/react-table"; import { useMemo, useState } from "react"; import { ApiKey } from "../lib/hexclave-app/api-keys"; type ExtendedApiKey = ApiKey & { status: 'valid' | 'expired' | 'revoked', }; function toolbarRender(table: Table) { return ( <> ({ value: provider, label: provider, }))} /> ); } function RevokeDialog(props: { apiKey: ExtendedApiKey, open: boolean, onOpenChange: (open: boolean) => void, }) { return { await props.apiKey.revoke(); } }} confirmText="I understand this will unlink all the apps using this API key" > {`Are you sure you want to revoke API key *****${props.apiKey.value.lastFour}?`} ; } function Actions({ row }: { row: Row }) { const [isRevokeModalOpen, setIsRevokeModalOpen] = useState(false); return ( <> setIsRevokeModalOpen(true), }]} /> ); } const columns: ColumnDef[] = [ { accessorKey: "description", header: ({ column }) => , cell: ({ row }) => {row.original.description}, }, { accessorKey: "status", header: ({ column }) => , cell: ({ row }) => , filterFn: standardFilterFn, }, { id: "value", accessorFn: (row) => row.value.lastFour, header: ({ column }) => , cell: ({ row }) => *******{row.original.value.lastFour}, enableSorting: false, }, { accessorKey: "expiresAt", header: ({ column }) => , cell: ({ row }) => { if (row.original.status === 'revoked') return -; return row.original.expiresAt ? : Never; }, }, { accessorKey: "createdAt", header: ({ column }) => , cell: ({ row }) => }, { id: "actions", cell: ({ row }) => , }, ]; export function ApiKeyTable(props: { apiKeys: ApiKey[] }) { const extendedApiKeys = useMemo(() => { const keys = props.apiKeys.map((apiKey) => ({ ...apiKey, status: ({ 'valid': 'valid', 'manually-revoked': 'revoked', 'expired': 'expired' } as const)[apiKey.whyInvalid() || 'valid'], } satisfies ExtendedApiKey)); // first sort based on status, then by createdAt return keys.sort((a, b) => { if (a.status === b.status) { return a.createdAt < b.createdAt ? 1 : -1; } return a.status === 'valid' ? -1 : 1; }); }, [props.apiKeys]); return ; }