4.7 KiB
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 ใหม่ ให้ระบบตั้งสถานะอัตโนมัติเป็น:
new_job
หรือ label:
New Job
User ไม่ต้องเลือกเองในหน้า Create
3. Default Marketing Owner
Marketing Owner ต้อง default เป็นผู้สร้างเอกสาร
marketingOwnerId = currentUser.id
ไม่ต้องให้ user เลือกตอน Create
4. Add Lead Source field
เพิ่ม field:
Lead Source
ใช้เก็บที่มาของ Lead เช่น:
- Website
- 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 typechecknpm run build
Implementation Result - 2026-07-01
Status: Completed
Implemented:
- Simplified Create Lead UX by hiding
Lost Reason,Status, andMarketing Ownerfrom create mode while keeping them available in edit mode. - Forced create default rules server-side so new leads always open with
new_jobstatus,openoutcome, no lost reason, andownerMarketingUserId = current user. - Added persisted
leadChannelsupport oncrm_leadsand exposed it in the UI asLead Source. - Reused the existing
crm_lead_channelmaster-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-> PASSnpm run build-> PASSnpm 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.sqlplus a journal entry for the newlead_channelcolumn and removal of the old rawstatusdefault oncrm_leads.
Implementation report: