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 (

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

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.

} /> } />
); }