import CertificateDetail from "@/components/certificate/CertificateDetail"; import { Button } from "@/components/ui/button"; import { DataTable } from "@/components/workflow/DataTable"; import { Certificate as CertificateType } from "@/domain/certificate"; import { diffDays, getLeftDays } from "@/lib/time"; import { list } from "@/repository/certificate"; import { ColumnDef } from "@tanstack/react-table"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate, useSearchParams } from "react-router-dom"; type CertificateListProps = { withPagination?: boolean; }; const CertificateList = ({ withPagination }: CertificateListProps) => { const [data, setData] = useState([]); const [pageCount, setPageCount] = useState(0); const [open, setOpen] = useState(false); const [selectedCertificate, setSelectedCertificate] = useState(); const { t } = useTranslation(); const [searchParams] = useSearchParams(); const fetchData = async (page: number, pageSize?: number) => { const state = searchParams.get("state"); const resp = await list({ page: page, perPage: pageSize, state: state ?? "" }); setData(resp.items); setPageCount(resp.totalPages); }; const navigate = useNavigate(); const columns: ColumnDef[] = [ { accessorKey: "san", header: t("certificate.props.domain"), cell: ({ row }) => { let san: string = row.getValue("san"); if (!san) { san = ""; } return (
{san.split(";").map((item, i) => { return (
{item}
); })}
); }, }, { accessorKey: "expireAt", header: t("certificate.props.expiry"), cell: ({ row }) => { const expireAt: string = row.getValue("expireAt"); const data = row.original; const leftDays = getLeftDays(expireAt); const allDays = diffDays(data.expireAt, data.created); return (
{leftDays > 0 ? (
{leftDays} / {allDays} {t("certificate.props.expiry.days")}
) : (
{t("certificate.props.expiry.expired")}
)}
{new Date(expireAt).toLocaleString().split(" ")[0]} {t("certificate.props.expiry.text.expire")}
); }, }, { accessorKey: "workflow", header: t("certificate.props.workflow"), cell: ({ row }) => { const name = row.original.expand.workflow?.name; const workflowId: string = row.getValue("workflow"); return (
); }, }, { accessorKey: "created", header: t("certificate.props.created"), cell: ({ row }) => { const date: string = row.getValue("created"); return new Date(date).toLocaleString(); }, }, { id: "actions", cell: ({ row }) => { return (
); }, }, ]; const handleWorkflowClick = (id: string) => { navigate(`/workflow/detail?id=${id}`); }; const handleView = (id: string) => { setOpen(true); const certificate = data.find((item) => item.id === id); setSelectedCertificate(certificate); }; return ( <>
{t("certificate.nodata")}
} /> ); }; export default CertificateList;