"use client"; import { Button } from "@/components/ui/button"; import { FileBadge, RotateCw } from "lucide-react"; import { useCertificate } from "@app/hooks/useCertificate"; import type { GetCertificateResponse } from "@server/routers/certificates/types"; import { useTranslations } from "next-intl"; export type CertificateStatusContentProps = { cert: GetCertificateResponse | null; certLoading: boolean; certError: string | null; refreshing: boolean; refreshCert: () => Promise; showLabel?: boolean; className?: string; onRefresh?: () => void; }; /** Presentation-only certificate row (shared hook state possible via props). */ export function CertificateStatusContent({ cert, certLoading, certError, refreshing, refreshCert, showLabel = true, className = "", onRefresh }: CertificateStatusContentProps) { const t = useTranslations(); const labelClass = "inline-flex shrink-0 items-center self-center text-sm font-medium leading-none"; const valueClass = "inline-flex items-center gap-2 text-sm leading-none"; const handleRefresh = async () => { await refreshCert(); onRefresh?.(); }; const getStatusColor = (status: string) => { switch (status) { case "valid": return "text-green-500"; case "pending": case "requested": return "text-yellow-500"; case "expired": case "failed": return "text-red-500"; default: return "text-muted-foreground"; } }; const shouldShowRefreshButton = (status: string, updatedAt: number) => { return ( status === "failed" || status === "expired" || (status === "requested" && updatedAt && new Date(updatedAt * 1000).getTime() < Date.now() - 5 * 60 * 1000) ); }; if (certLoading) { return (
{showLabel && ( {t("certificateStatus")}: )} {t("loading")}
); } if (certError) { return (
{showLabel && ( {t("certificateStatus")}: )} {certError}
); } if (!cert) { return (
{showLabel && ( {t("certificateStatus")}: )} {t("none", { defaultValue: "None" })}
); } const isPending = cert.status === "pending"; const disableRestartButton = cert.domainType === "wildcard"; return (
{showLabel && ( {t("certificateStatus")}: )} {isPending && !disableRestartButton ? ( ) : ( {cert.status.charAt(0).toUpperCase() + cert.status.slice(1)} {shouldShowRefreshButton(cert.status, cert.updatedAt) && !disableRestartButton ? ( ) : null} )}
); } type CertificateStatusProps = { orgId: string; domainId: string; fullDomain: string; autoFetch?: boolean; showLabel?: boolean; className?: string; onRefresh?: () => void; polling?: boolean; pollingInterval?: number; }; export default function CertificateStatus({ orgId, domainId, fullDomain, autoFetch = true, showLabel = true, className = "", onRefresh, polling = false, pollingInterval = 5000 }: CertificateStatusProps) { const hook = useCertificate({ orgId, domainId, fullDomain, autoFetch, polling, pollingInterval }); return ( ); }