import { Table, Text, Group, Skeleton, Anchor, Badge, Avatar, Tooltip, } from "@mantine/core"; import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { IVerificationListItem, VerificationStatus, } from "@/ee/page-verification/types/page-verification.types"; import { CustomAvatar } from "@/components/ui/custom-avatar"; import { buildPageUrl } from "@/features/page/page.utils"; import { format } from "date-fns"; import NoTableResults from "@/components/common/no-table-results"; const MAX_VISIBLE_VERIFIERS = 5; type VerificationListTableProps = { items?: IVerificationListItem[]; isLoading: boolean; }; function statusBadge(status: VerificationStatus | null, t: (s: string) => string) { switch (status) { case "verified": return {t("Verified")}; case "expiring": return {t("Expiring")}; case "expired": return {t("Expired")}; case "approved": return {t("Approved")}; case "draft": return {t("Draft")}; case "in_approval": return {t("In approval")}; case "obsolete": return {t("Obsolete")}; default: return null; } } function verifiedUntilText(item: IVerificationListItem, t: (s: string) => string): string { if (item.type === "qms") { if (item.status === "approved") return t("Indefinitely"); return "—"; } if (!item.expiresAt) return t("Indefinitely"); const expires = new Date(item.expiresAt); const now = new Date(); if (expires <= now) return t("Expired"); return format(expires, "MMM d, yyyy"); } function TableSkeleton() { return ( <> {Array.from({ length: 8 }).map((_, i) => (
))} ); } export default function VerificationListTable({ items, isLoading, }: VerificationListTableProps) { const { t } = useTranslation(); return ( {t("Page")} {t("Verifiers")} {t("Verified until")} {t("Status")} {isLoading ? ( ) : items && items.length > 0 ? ( items.map((item) => { const verifiers = item.verifiers ?? []; const pageUrl = buildPageUrl( item.spaceSlug, item.pageSlugId, item.pageTitle ?? undefined, ); return ( {item.pageIcon ? `${item.pageIcon} ` : ""} {item.pageTitle || t("Untitled")} {item.spaceName} {verifiers.length === 1 ? ( {verifiers[0].name} ) : verifiers.length > 1 ? ( {verifiers .slice(0, MAX_VISIBLE_VERIFIERS) .map((verifier) => ( ))} {verifiers.length > MAX_VISIBLE_VERIFIERS && ( (
{v.name}
))} > +{verifiers.length - MAX_VISIBLE_VERIFIERS}
)}
) : ( )}
{verifiedUntilText(item, t)} {statusBadge(item.status as VerificationStatus, t)}
); }) ) : ( )}
); }