Files
pn-new-crm/src/app/api/v1/documents/template-defaults/route.ts

44 lines
1.5 KiB
TypeScript
Raw Normal View History

feat(wizard-refactor): drop inapp pathway + upload branch + per-port template defaults + mark-signed dropdown Phase 2 of the comprehensive UAT round. Locked decisions from the 2026-05-26 question round (see docs/superpowers/audits/active-uat.md "Decisions locked" block). P2.1 — drop the inapp template pathway Removed the dead pathway dropdown. Generate-from-template flow is now exclusively documenso-template; the inapp (pdf-lib + CRM-render) branch was never surfaced as a deliberate choice and was a config trap. Server-side route still accepts pathway='inapp' for backcompat with older clients - wizard now always sends 'documenso-template'. P2.2 — delete the wizard's upload branch Reps who want to upload a finished PDF go through the New-document dropdown -> "Upload & send for signature" (UploadForSigningDialog, the proper field-placement flow) instead of the wizard's half-implemented upload sub-form. Wizard's Source section becomes a one-line explainer + the template picker; no more redundant radio-then-pathway-then-template layering. P2.3 — per-port doc-type template defaults New GET /api/v1/documents/template-defaults endpoint returns { eoi, contract, reservation_agreement } template ids from getPortDocumensoConfig. Settings registry keys already existed for contract + reservation; config + resolver already plumbed them. CreateDocumentWizard now fetches the map on mount and auto-sets templateId whenever documentType changes (empty picker OR currently showing a different doc-type's default both get re-aligned). Admin override via the picker still works. P2.4 — surface flow 3 (mark signed offline) from the dropdown NewDocumentMenu gains a 4th item: "Mark as signed (offline)". Opens a small dialog that asks for the interest + doc type (eoi/reservation/contract), then navigates to the matching per-interest tab with ?tab=...&action=upload-signed query param. Per-interest tabs are the single source of truth for the pipeline-stage + doc-status side effects of the mark-signed flow; the hub-level dropdown just routes the rep to the right place. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 21:17:17 +02:00
import { NextResponse } from 'next/server';
import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getPortDocumensoConfig } from '@/lib/services/port-config';
/**
* GET `/api/v1/documents/template-defaults`
*
* Returns the per-port default Documenso template id keyed by
* documentType. The CreateDocumentWizard reads this to auto-resolve
* the template the rep doesn't have to remember picking "EOI" /
* "Reservation Agreement" / "Contract" defaults to the matching port
* template id. Admins with the explicit perm can still override via
* the DocumentTemplatePicker.
*
* Permission: documents.create the only caller is the wizard which
* already requires this permission to complete the flow. View-only
* roles don't see the wizard at all.
*
* Response:
* { data: { eoi: number | null, contract: number | null,
* reservation_agreement: number | null } }
*
* `null` means no template configured for that doc type (rep must
* pick one manually via the override picker).
*/
export const GET = withAuth(
withPermission('documents', 'create', async (_req, ctx) => {
try {
const cfg = await getPortDocumensoConfig(ctx.portId);
return NextResponse.json({
data: {
eoi: cfg.eoiTemplateId > 0 ? cfg.eoiTemplateId : null,
contract: cfg.contractTemplateId,
reservation_agreement: cfg.reservationTemplateId,
},
});
} catch (error) {
return errorResponse(error);
}
}),
);