# Task J.1: CRM Admin Configuration Center

## Files Added

- `src/app/api/crm/settings/**`
- `src/app/dashboard/crm/settings/approval-workflows/page.tsx`
- `src/features/foundation/approval/components/approval-workflow-settings.tsx`
- `src/features/foundation/document-sequence/client-service.ts`
- `src/features/foundation/document-sequence/components/document-sequence-settings.tsx`
- `src/features/foundation/document-sequence/mutations.ts`
- `src/features/foundation/document-sequence/queries.ts`
- `src/features/foundation/document-template/mutations.ts`
- `docs/implementation/task-j1-crm-admin-configuration-center.md`

## Files Modified

- `src/config/nav-config.ts`
- `src/lib/auth/rbac.ts`
- `src/app/dashboard/crm/settings/document-sequences/page.tsx`
- `src/features/foundation/approval/{mutations,queries,server/service,service,types}.ts`
- `src/features/foundation/document-sequence/{service,types}.ts`
- `src/features/foundation/document-template/{components/template-settings,mutations,server/service,service,types}.ts`

## What Was Added

- CRM Settings menu now includes `Approval Workflows` and uses CRM-specific permission checks for `Document Sequences`.
- `/dashboard/crm/settings/templates` now supports:
  - create/edit template metadata
  - create/edit template versions with JSON schema textarea
  - create/edit/delete template mappings
  - table-column mapping input for `table` data type
- `/dashboard/crm/settings/approval-workflows` now supports:
  - create/edit/delete workflows
  - manage sequential workflow steps
  - role-based step definitions using CRM business roles
- `/dashboard/crm/settings/document-sequences` now supports:
  - create/edit/delete sequences
  - reset sequence counters
  - preview next code from stored sequence state

## API Routes Added

- `/api/crm/settings/document-templates/**`
- `/api/crm/settings/approval-workflows/**`
- `/api/crm/settings/document-sequences/**`

## Permissions Added

- `crm.approval.workflow.read`
- `crm.approval.workflow.create`
- `crm.approval.workflow.update`
- `crm.approval.workflow.delete`
- `crm.document_sequence.read`
- `crm.document_sequence.create`
- `crm.document_sequence.update`
- `crm.document_sequence.reset`

## Audit Coverage

- `crm_document_template_version`
- `crm_document_template_mapping`
- `crm_approval_workflow`
- `crm_approval_step`
- `crm_document_sequence`

## Verification

- `npx tsc --noEmit` passed on June 17, 2026.
- `npm run lint` still fails because of pre-existing repo lint errors outside Task J.1 scope, including:
  - `src/components/ui/input-group.tsx`
  - `src/features/chat/components/message-composer.tsx`
  - `src/components/forms/demo-form.tsx`

## Remaining Risks

- Template settings UI is functional but not yet a polished table-first admin experience.
- Document template version activation currently supports state updates, but the page focuses on version edit/create over dedicated activate/deactivate action buttons.
- Sequence reset UI currently resets to `0`; custom reset value can be added later if the product needs it.
- Approval step management currently replaces the full ordered step list in one save flow rather than exposing per-row move controls.

## Task K Readiness

- CRM settings foundations are now exposed through organization-scoped admin routes.
- Query invalidation is wired for template, workflow, and sequence mutations.
- The configuration center is ready for KPI/report consumers to reference the same settings data in later tasks.
