# Task D.3.1: Leads / Enquiries Navigation Separation

## Goal

แยกเมนู Leads และ Enquiries ออกจากกันเพื่อลดความสับสนของผู้ใช้งาน

Business Process ยังคงเป็น:

```txt
Lead
↓ Assign To Sales
Enquiry
↓
Quotation
↓
Won / Lost
```

แต่ UX จะถูกแยกเป็น 2 Workspace

```txt
CRM
├── Dashboard
├── Leads
├── Enquiries
├── Quotations
├── Approvals
└── Settings
```

Important:

Task นี้เป็น UX Separation เท่านั้น

Do NOT create:

```txt
crm_leads
```

Do NOT duplicate:

```txt
API
Schema
Database
Server Service
```

ยังคงใช้

```txt
crm_enquiries
```

เป็น Single Source of Truth

---

# Scope D3.1.1 Navigation

Update:

```txt
src/config/nav-config.ts
```

Add:

```txt
CRM
 ├ Leads
 └ Enquiries
```

Remove old combined menu if exists.

Permissions:

Leads menu:

```txt
crm.lead.read
```

Enquiries menu:

```txt
crm.enquiry.read
```

---

# Scope D3.1.2 Routes

Add:

```txt
/dashboard/crm/leads
/dashboard/crm/leads/[id]
```

Keep:

```txt
/dashboard/crm/enquiries
/dashboard/crm/enquiries/[id]
```

Rules:

Leads page:

```txt
pipelineStage = lead
```

Enquiries page:

```txt
pipelineStage = enquiry
```

---

# Scope D3.1.3 Reuse Existing Module

Do NOT create:

```txt
src/features/crm/leads
```

Reuse:

```txt
src/features/crm/enquiries/**
```

Implementation pattern:

```ts
getEnquiries({
  pipelineStage: "lead"
})

getEnquiries({
  pipelineStage: "enquiry"
})
```

Shared:

```txt
API
Types
Mutations
Queries
Schema
Server Service
```

---

# Scope D3.1.4 Leads UI

Leads page should focus on Marketing workflow.

Columns:

```txt
Code
Lead Source
Company
Contact
Assigned Sales
Created By
Created At
Age
Status
```

Actions:

```txt
View
Edit
Assign To Sales
Mark Lost
```

Hide:

```txt
Quotation Count
Revenue
Chance %
Quotation Value
```

---

# Scope D3.1.5 Enquiries UI

Enquiries page should focus on Sales workflow.

Columns:

```txt
Code
Project
Billing Customer
Enquiry Owner
Chance %
Estimated Value
Quotation Count
Next Follow-up
Status
```

Actions:

```txt
View
Edit
Create Quotation
Follow-up
Won
Lost
```

---

# Scope D3.1.6 Detail Page Labels

Lead Detail:

```txt
Lead Information
Lead Source
Lead Owner
Assigned Sales
```

Enquiry Detail:

```txt
Enquiry Information
Project Information
Enquiry Owner
Follow-ups
Quotations
```

Both pages may internally reuse the same component.

Only labels and visibility differ.

---

# Scope D3.1.7 Permissions

Add:

```txt
crm.lead.read
crm.lead.create
crm.lead.update
crm.lead.assign
crm.lead.delete
```

Map existing behavior:

```txt
marketing
admin
super_admin
```

Default:

Marketing:

```txt
Lead permissions
```

Sales:

```txt
Enquiry permissions
```

Managers:

```txt
Both
```

---

# Scope D3.1.8 Dashboard Alignment

Dashboard cards should use:

Lead:

```txt
pipelineStage = lead
```

Enquiry:

```txt
pipelineStage = enquiry
```

Links:

```txt
Lead KPI
→ /dashboard/crm/leads

Enquiry KPI
→ /dashboard/crm/enquiries
```

---

# Scope D3.1.9 Query Freshness

After:

```txt
Assign Lead
Convert Lead → Enquiry
Won
Lost
```

Invalidate:

```txt
lead list
enquiry list
lead detail
enquiry detail
dashboard KPI
```

Rules:

Assigned lead should disappear from Leads immediately and appear in Enquiries immediately.

No manual refresh allowed.

---

# Scope D3.1.10 ADR Update

Update:

```txt
docs/adr/0011-lead-enquiry-ownership-model.md
```

Add section:

```txt
Navigation Separation
```

Document:

```txt
Lead and Enquiry are separate UX workspaces.

Lead and Enquiry are NOT separate domain entities.

Both are stored in crm_enquiries.

pipelineStage determines business state.
```

---

# Explicit Non-Scope

Do NOT implement:

```txt
crm_leads table
Lead API
Lead schema
Lead server service
Campaign module
Lead scoring
Marketing automation
Import/Export redesign
```

---

# Output

1. Files Added
2. Files Modified
3. Navigation Changes
4. Route Changes
5. Permission Changes
6. Query Invalidation Added
7. Dashboard Changes
8. ADR Updates
9. Remaining Risks

---

# Definition of Done

✔ Leads menu exists

✔ Enquiries menu exists

✔ Leads page shows only lead-stage records

✔ Enquiries page shows only enquiry-stage records

✔ Lead assignment moves record between pages immediately

✔ Dashboard links point correctly

✔ No duplicate lead module created

✔ No new database table created

✔ Existing enquiry APIs reused

✔ ADR updated
