# Task D3.1: Leads / Enquiries Navigation Separation

## Files Added

- `src/app/dashboard/crm/leads/page.tsx`
- `src/app/dashboard/crm/leads/[id]/page.tsx`
- `docs/implementation/task-d31-leads-enquiries-navigation-separation.md`

## Files Modified

- `src/config/nav-config.ts`
- `src/lib/auth/rbac.ts`
- `src/app/dashboard/crm/enquiries/page.tsx`
- `src/app/dashboard/crm/enquiries/[id]/page.tsx`
- `src/app/api/crm/enquiries/route.ts`
- `src/features/crm/dashboard/components/dashboard-summary-cards.tsx`
- `src/features/crm/enquiries/api/types.ts`
- `src/features/crm/enquiries/api/service.ts`
- `src/features/crm/enquiries/api/mutations.ts`
- `src/features/crm/enquiries/components/enquiry-listing.tsx`
- `src/features/crm/enquiries/components/enquiries-table.tsx`
- `src/features/crm/enquiries/components/enquiry-columns.tsx`
- `src/features/crm/enquiries/components/enquiry-cell-action.tsx`
- `src/features/crm/enquiries/components/enquiry-form-sheet.tsx`
- `src/features/crm/enquiries/components/enquiry-detail.tsx`
- `src/features/crm/enquiries/server/service.ts`
- `docs/adr/0011-lead-enquiry-ownership-model.md`

## Navigation Changes

- Split the combined CRM workspace into `Leads` and `Enquiries`.
- Kept a single shared feature module by reusing `src/features/crm/enquiries/**`.

## Route Changes

- Added `/dashboard/crm/leads`
- Added `/dashboard/crm/leads/[id]`
- Reused the same list/detail backend and scoped each page with `pipelineStage`
- Redirected lead detail to enquiry detail when the record has already moved past the `lead` stage

## Permission Changes

- Added:
  - `crm.lead.read`
  - `crm.lead.create`
  - `crm.lead.update`
  - `crm.lead.assign`
  - `crm.lead.delete`
- Mapped `marketing` to lead-centric permissions
- Kept `sales` on enquiry-centric permissions
- Gave manager roles both lead and enquiry capabilities

## Query Invalidation Added

- CRM enquiry mutations now invalidate lead/enquiry list queries, detail queries, follow-up queries, and CRM dashboard KPI queries.
- Assigned leads now disappear from the Leads workspace and appear in the Enquiries workspace without manual refresh.

## Dashboard Changes

- Lead KPI card links to `/dashboard/crm/leads`
- Enquiry KPI card links to `/dashboard/crm/enquiries`
- List filtering now accepts `pipelineStage` for workspace drill-down

## ADR Updates

- Added a `Navigation Separation` section to ADR 0011
- Clarified that lead/enquiry are UX workspaces, not separate persisted entities

## Remaining Risks

- Shared route handlers still live under the enquiry API namespace by design, so the lead workspace depends on the shared `crm_enquiries` backend contract.
- Manager permission breadth may need later refinement if `department_manager` and `top_manager` should diverge.
