import { CheckCircle2, Info } from 'lucide-react';
import {
SettingsFormCard,
type SettingFieldDef,
} from '@/components/admin/shared/settings-form-card';
import { RegistryDrivenForm } from '@/components/admin/shared/registry-driven-form';
import { DocumensoTestButton } from '@/components/admin/documenso/documenso-test-button';
import { EmbeddedSigningCard } from '@/components/admin/documenso/embedded-signing-card';
import { TemplateSyncButton } from '@/components/admin/documenso/template-sync-button';
import { PageHeader } from '@/components/shared/page-header';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
// API_FIELDS removed — replaced by
// which adds the new webhook-secret field + AES encrypts the API key at rest.
const CONTRACT_RESERVATION_FIELDS: SettingFieldDef[] = [
{
key: 'documenso_contract_template_id',
label: 'Contract Documenso template ID (optional)',
description:
'Numeric template ID for sales contract generation. Leave blank to use the per-interest upload-and-place-fields flow instead (the typical path for contracts, since they are usually drafted custom per client).',
type: 'string',
placeholder: '',
defaultValue: '',
},
{
key: 'documenso_reservation_template_id',
label: 'Reservation agreement Documenso template ID (optional)',
description:
'Numeric template ID for reservation agreements. Same logic — leave blank to upload per interest.',
type: 'string',
placeholder: '',
defaultValue: '',
},
];
// Embedded signing field config + Test + Setup help all live inside
// `` (imported above). Kept out of the field list
// here so the admin page reads as a flat sequence of cards.
const V2_FEATURE_FIELDS: SettingFieldDef[] = [
{
key: 'documenso_signing_order',
label: 'Signing order',
description:
'Whether all signers receive the invitation at once (PARALLEL — anyone can sign first) or only the next pending signer gets the email once the previous one finishes (SEQUENTIAL). Applied at envelope-create time on both v1 and v2: v1 honours meta.signingOrder on /templates/{id}/generate-document; v2 honours it via /envelope/update right after /template/use.',
type: 'select',
options: [
{ value: 'PARALLEL', label: 'PARALLEL — all signers invited at once' },
{ value: 'SEQUENTIAL', label: 'SEQUENTIAL — one at a time in order' },
],
defaultValue: 'PARALLEL',
},
{
key: 'documenso_redirect_url',
label: 'Post-signing redirect URL',
description:
"URL Documenso redirects the signer to after they complete signing. Typically the marketing site's success page so signers land on a branded thank-you rather than Documenso's own page. Leave blank to use Documenso's default. v1 and v2 both honour this. Example: https://portnimara.com/sign/success",
type: 'string',
placeholder: 'https://portnimara.com/sign/success',
defaultValue: '',
},
];
export default function DocumensoSettingsPage() {
return (
v1 vs v2 — what changes when you flip the API version
The CRM supports both Documenso 1.13.x (v1) and 2.x (v2). v1 is the default for
backwards compatibility. v2 is recommended for new ports and unlocks the features below.
Switching versions does not require any code changes — version-aware
client methods pick the right endpoint per port. Switch, save, then run the
test-connection button to confirm the chosen instance is actually on the matching
Documenso version.
v2-only capabilities the CRM already uses when you pick v2
-
Bulk field placement. One API call per envelope vs. v1's
per-field POST loop. Faster contract generation, fewer transient retries on
multi-field uploaded contracts.
-
Percent-based field coordinates. No page-dimension lookup needed
— coordinates are portable across page sizes. v1 requires us to assume A4 for
auto-placed fields.
-
Richer field metadata. TEXT labels & required flags, NUMBER
min/max + format, CHECKBOX/DROPDOWN/RADIO option lists with defaults — all ignored
by v1, surfaced by v2 in the signing UI.
-
v2-flavoured webhook events.
RECIPIENT_VIEWED,{' '}
RECIPIENT_SIGNED, DOCUMENT_RECIPIENT_COMPLETED,{' '}
DOCUMENT_DECLINED, DOCUMENT_REMINDER_SENT — all routed
through the same dedup + audit pipeline as v1 events.
-
Envelope CRUD endpoints.
GET, DELETE,
POST /envelope/create (multipart),{' '}
POST /envelope/distribute, POST /envelope/redistribute,{' '}
GET /envelope/{'{id}'}/download — all routed through{' '}
/api/v2/envelope/... when v2 is selected. The template-generate path
is intentionally still v1 (relies on Documenso 2.x's backward-compat window —
see the deferred-roadmap below).
-
One-call send. v2's
/envelope/distribute{' '}
returns per-recipient signingUrl in the same response — v1 requires a
separate GET to fetch them. Faster send flow on the rep side.
-
Sequential signing enforcement. Pick SEQUENTIAL in the "v2
signing behaviour" card below and Documenso 2.x refuses to email recipient
N+1 until recipient N has signed. Eliminates the "approver signed before the
developer did" race on EOIs.
-
Post-signing redirect URL. Set in the "v2 signing
behaviour" card; Documenso redirects the signer to that URL after they
complete signing. Use to land clients on the marketing site's success page or
back in the portal instead of Documenso's default thank-you page. (v1 honours
this too — listed here because the admin setting was added with the v2 work.)
v2 capabilities deferred (would need new code paths)
-
Single-shot
/template/use
{' '}
with v2 prefillFields by ID — current EOI flow uses{' '}
/api/v1/templates/{'{id}'}/generate-document with{' '}
formValues keyed by name. v2 instances accept both during their
backward-compat window; full migration requires per-template field-ID capture in
admin settings.
-
Update envelope metadata after creation (
/envelope/update)
{' '}
— change title / subject / redirectUrl on a doc already in DRAFT/PENDING without
re-generating.
-
Non-SIGNER recipient roles (CC / VIEWER) — APPROVER role is already
used by the EOI template; CC + VIEWER not yet exposed in the recipient builder.
Useful for sales managers who want a copy without a signature slot.
Sequential signing and post-signing redirect URL are now wired — see
the new "v2 signing behaviour" card below to configure them.
}
/>
}
/>
);
}