import { IconDotsVertical, IconDownload, IconRefresh, IconTrash } from "@tabler/icons-react"; import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table"; import { useMemo } from "react"; import type { Certificate } from "src/api/backend"; import { CertificateInUseFormatter, DateFormatter, DomainsFormatter, EmptyData, GravatarFormatter, } from "src/components"; import { TableLayout } from "src/components/Table/TableLayout"; import { intl, T } from "src/locale"; import { showCustomCertificateModal, showDNSCertificateModal, showHTTPCertificateModal } from "src/modals"; interface Props { data: Certificate[]; isFiltered?: boolean; isFetching?: boolean; onDelete?: (id: number) => void; onRenew?: (id: number) => void; onDownload?: (id: number) => void; } export default function Table({ data, isFetching, onDelete, onRenew, onDownload, isFiltered }: Props) { const columnHelper = createColumnHelper(); const columns = useMemo( () => [ columnHelper.accessor((row: any) => row.owner, { id: "owner", cell: (info: any) => { const value = info.getValue(); return ; }, meta: { className: "w-1", }, }), columnHelper.accessor((row: any) => row, { id: "domainNames", header: intl.formatMessage({ id: "column.name" }), cell: (info: any) => { const value = info.getValue(); return ( ); }, }), columnHelper.accessor((row: any) => row, { id: "provider", header: intl.formatMessage({ id: "column.provider" }), cell: (info: any) => { const r = info.getValue(); if (r.provider === "letsencrypt") { if (r.meta?.dnsChallenge && r.meta?.dnsProvider) { return ( <> – {r.meta?.dnsProvider} ); } return ; } if (r.provider === "other") { return ; } return ; }, }), columnHelper.accessor((row: any) => row.expiresOn, { id: "expiresOn", header: intl.formatMessage({ id: "column.expires" }), cell: (info: any) => { return ; }, }), columnHelper.accessor((row: any) => row, { id: "proxyHosts", header: intl.formatMessage({ id: "column.status" }), cell: (info: any) => { const r = info.getValue(); return ( ); }, }), columnHelper.display({ id: "id", cell: (info: any) => { return (
{ e.preventDefault(); onRenew?.(info.row.original.id); }} > { e.preventDefault(); onDownload?.(info.row.original.id); }} > ); }, meta: { className: "text-end w-1", }, }), ], [columnHelper, onDelete, onRenew, onDownload], ); const tableInstance = useReactTable({ columns, data, getCoreRowModel: getCoreRowModel(), rowCount: data.length, meta: { isFetching, }, enableSortingRemoval: false, }); const customAddBtn = (