Files
alla-allaos-fullstack/plans/task-d.6.1.md
phaichayon 0a144f0f9e task-d.6.1
2026-07-01 10:29:00 +07:00

154 lines
4.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Task D.6.1 Lead Create Form UX & Default Rules
## Objective
ปรับหน้า Create Lead ให้เหมาะกับการสร้าง Lead ใหม่จริง โดยซ่อน field ที่ยังไม่ควรใช้ตอนเริ่มต้น และตั้งค่า default ตาม business rule
---
## Requirements
### 1. Hide fields on Create Lead
ตอนสร้าง Lead ใหม่ ไม่ต้องแสดง field ต่อไปนี้:
* Lost Reason
* Status
* Marketing Owner
Field เหล่านี้อาจแสดงในหน้า Edit/Detail ตาม permission และสถานะภายหลังได้
---
### 2. Default Lead Status
เมื่อสร้าง Lead ใหม่ ให้ระบบตั้งสถานะอัตโนมัติเป็น:
```text
new_job
```
หรือ label:
```text
New Job
```
User ไม่ต้องเลือกเองในหน้า Create
---
### 3. Default Marketing Owner
Marketing Owner ต้อง default เป็นผู้สร้างเอกสาร
```text
marketingOwnerId = currentUser.id
```
ไม่ต้องให้ user เลือกตอน Create
---
### 4. Add Lead Source field
เพิ่ม field:
```text
Lead Source
```
ใช้เก็บที่มาของ Lead เช่น:
* Website
* Facebook
* Line OA
* Phone Call
* Walk-in
* Referral
* Existing Customer
* Exhibition
* Sales Visit
* Other
ควรใช้ master option / ms_options ถ้ามี foundation รองรับอยู่แล้ว
---
## Create vs Edit Behavior
### Create Lead
แสดงเฉพาะ field ที่จำเป็นสำหรับเปิด Lead ใหม่
ไม่แสดง:
* Lost Reason
* Status
* Marketing Owner
ระบบกำหนดให้อัตโนมัติ
---
### Edit Lead / Detail Lead
สามารถแสดง field เพิ่มเติมตามสถานะและ permission เช่น:
* Status
* Lost Reason เมื่อ status เป็น lost/closed lost
* Marketing Owner สำหรับ admin/manager ถ้าต้อง reassign
---
## Backend Rules
ฝั่ง API/service ต้อง enforce ด้วย ไม่พึ่ง UI อย่างเดียว:
* ถ้า create lead ไม่มี status → set `new_job`
* ถ้า create lead ไม่มี marketingOwnerId → set current user
* ห้าม user override marketingOwnerId ถ้าไม่มี permission
* Lost Reason ต้องไม่ required ตอน create
* Lead Source ควรถูก validate จาก master option
---
## Acceptance Criteria
* Create Lead ไม่แสดง Lost Reason
* Create Lead ไม่แสดง Status
* Create Lead ไม่แสดง Marketing Owner
* Lead ใหม่ถูกสร้างด้วย status `New Job`
* Marketing Owner เป็น user ที่สร้าง Lead
* มี field Lead Source
* Lead Source บันทึกได้ถูกต้อง
* Edit/Detail ยังรองรับ status/lost reason ตาม business rule
* `npm run typecheck`
* `npm run build`
---
# Implementation Result - 2026-07-01
Status: Completed
Implemented:
- Simplified Create Lead UX by hiding `Lost Reason`, `Status`, and `Marketing Owner` from create mode while keeping them available in edit mode.
- Forced create default rules server-side so new leads always open with `new_job` status, `open` outcome, no lost reason, and `ownerMarketingUserId = current user`.
- Added persisted `leadChannel` support on `crm_leads` and exposed it in the UI as `Lead Source`.
- Reused the existing `crm_lead_channel` master-option foundation for the new Lead Source select field.
- Updated lead reference data, DTOs, server mapping, and detail view to carry and display `Lead Source`.
- Rebuilt the lead form around the repo's TanStack Form pattern with explicit create-vs-edit behavior.
Verification:
- `npm run typecheck` -> PASS
- `npm run build` -> PASS
- `npm run audit:pdf` -> PASS
Notes:
- Build still reports existing Turbopack warnings about workspace-root lockfile detection and broad file tracing in storage/template infrastructure. The task did not introduce a blocking build issue.
- Added migration file `drizzle/0001_lead_channel_and_status_default.sql` plus a journal entry for the new `lead_channel` column and removal of the old raw `status` default on `crm_leads`.
Implementation report:
- [task-d.6.1-lead-create-form-ux-default-rules-2026-07-01.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/implementation/task-d.6.1-lead-create-form-ux-default-rules-2026-07-01.md)