"use client" import { useTransition } from "react" import Link from "next/link" import { toast } from "sonner" import { PenLine, CheckCircle2, Clock, XCircle, AlertTriangle, Download } from "lucide-react" import { formatDate } from "@/lib/utils" import { sendLeaseForSignatureAction } from "@/app/actions/esign" type Req = { id: string provider: string status: string signer_email: string document_name: string | null signed_document_url: string | null sent_at: string | null completed_at: string | null last_error: string | null } type Prov = { id: string; label: string } const STATUS: Record = { sent: { label: "Awaiting signature", cls: "text-amber-400 bg-amber-500/10 border-amber-500/20", Icon: Clock }, signed: { label: "Signed", cls: "text-emerald-400 bg-emerald-500/10 border-emerald-500/20", Icon: CheckCircle2 }, declined: { label: "Declined", cls: "text-red-400 bg-red-500/10 border-red-500/20", Icon: XCircle }, voided: { label: "Voided", cls: "text-white/40 bg-white/5 border-white/10", Icon: XCircle }, error: { label: "Failed", cls: "text-red-400 bg-red-500/10 border-red-500/20", Icon: AlertTriangle }, } const PROVIDER_LABEL: Record = { docusign: "DocuSign", dropbox_sign: "Dropbox Sign" } export function EsignLease({ leaseId, connected, requests, canSend, disabledReason, }: { leaseId: string connected: Prov[] requests: Req[] canSend: boolean disabledReason: string }) { const [pending, start] = useTransition() function send(provider: string) { start(async () => { try { await sendLeaseForSignatureAction(leaseId, provider) toast.success("Lease sent for signature") } catch (e) { toast.error((e as Error).message || "Couldn't send for signature") } }) } return (

E-signature

{requests.length > 0 && (
    {requests.map((r) => { const s = STATUS[r.status] ?? STATUS.sent return (
  • {PROVIDER_LABEL[r.provider] ?? r.provider} · {r.signer_email}

    Sent {r.sent_at ? formatDate(r.sent_at) : "—"} {r.completed_at ? ` · Signed ${formatDate(r.completed_at)}` : ""} {r.status === "error" && r.last_error ? ` · ${r.last_error}` : ""}

    {r.signed_document_url && ( Signed document )}
    {s.label}
  • ) })}
)} {connected.length === 0 ? (

Connect DocuSign or Dropbox Sign {" "} in Settings → Integrations to send leases for signature.

) : canSend ? (
{connected.map((p) => ( ))}
) : (

{disabledReason}

)}
) }