This commit is contained in:
2026-07-16 09:53:14 +07:00
parent 0fc112a2e8
commit 29cec708a3
1236 changed files with 212848 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
# Training Course Dropdown Review
## Summary
ปรับฟอร์ม Create/Edit Training Record ให้แสดงฟิลด์หลักสูตรเป็น dropdown ตามค่าเริ่มต้น และแสดงช่องกรอกชื่อหลักสูตรเองเฉพาะเมื่อผู้ใช้เลือก `อื่น ๆ` โดยยังคงบันทึก `courseName` ทุกครั้ง และบันทึก `courseId` เฉพาะกรณีเลือกจาก Course Master
## Files Changed
- `src/features/training-records/components/training-record-form.tsx`
- `src/features/training-records/components/training-record-course-combobox.tsx`
- `src/features/training-records/schemas/training-record.ts`
## UI Changes
- ฟิลด์ `ชื่อหลักสูตร *` แสดงเป็น dropdown/select แบบเต็มความกว้าง
- รายการหลักสูตรแสดงจาก Active Course Master
- ตัวเลือกสุดท้ายของ dropdown คือ `อื่น ๆ`
- เมื่อเลือก `อื่น ๆ` จะเปลี่ยนเป็น text input แบบเต็มความกว้าง
## Course Dropdown Behavior
- dropdown แสดงหลักสูตร active เท่านั้น
- รูปแบบการแสดงผล:
- ถ้ามี `courseCode` ใช้ `courseCode - courseName`
- ถ้าไม่มี `courseCode` ใช้ `courseName`
- เมื่อเลือกหลักสูตรจาก master:
- ตั้งค่า `courseId`
- ตั้งค่า `courseName`
- auto-fill `organizer` ถ้ามี
- auto-fill `hours` จาก `standard_hours` ถ้ามี
## Custom Course Behavior
- เมื่อเลือก `อื่น ๆ`
- ซ่อน dropdown
- แสดง input `ชื่อหลักสูตรอื่น ๆ *`
- ตั้งค่า `courseId = null`
- ใช้ค่าจาก input ไปบันทึกเป็น `courseName`
- มีปุ่ม `เปลี่ยนกลับไปเลือกจากหลักสูตร`
- ล้างชื่อหลักสูตร custom
- กลับไปแสดง dropdown
- เคลียร์ `courseId` และ `courseName`
## Edit Mode Behavior
- ถ้า record เดิมมี `courseId`
- เปิดมาด้วย dropdown ที่เลือกหลักสูตรเดิมไว้
- ถ้า record เดิมมี `courseId = null` และมี `courseName`
- เปิดมาด้วย text input ของ custom course
- แสดงชื่อหลักสูตรเดิมใน input
## Validation Rules
- ถ้าไม่ได้เลือก `อื่น ๆ`:
- ต้องเลือกหลักสูตรจาก dropdown
- แสดงข้อความ `กรุณาเลือกหลักสูตร`
- ถ้าเลือก `อื่น ๆ`:
- ต้องกรอกชื่อหลักสูตร
- แสดงข้อความ `กรุณากรอกชื่อหลักสูตร`
- ชั่วโมงอบรมต้องมากกว่า 0
- แสดงข้อความ `กรุณาระบุจำนวนชั่วโมงอบรม`
## Database Behavior
- บันทึก `courseName` ทุกครั้ง
- ถ้าเลือกจาก Course Master:
- บันทึก `courseId`
- ถ้าเลือก `อื่น ๆ`:
- บันทึก `courseId = null`
- ไม่มีการลบ field `courseName`
## Manual Test Checklist
- Create form shows course dropdown by default.
- Active Course Master records are shown in dropdown.
- "อื่น ๆ" appears as the last option.
- Selecting Course Master saves courseId and courseName.
- Selecting Course Master auto-fills provider if available.
- Selecting Course Master auto-fills hours if available.
- Selecting "อื่น ๆ" changes dropdown to text input.
- Custom course name is required when "อื่น ๆ" is selected.
- "เปลี่ยนกลับไปเลือกจากหลักสูตร" works.
- Edit existing master course shows dropdown selected.
- Edit existing custom course shows text input.
- HRD review page still shows course name correctly.
- Reports still show course name correctly.
- Mobile layout works.
## Known Limitations
- งานนี้ยังใช้ query course list เดิมและดึงมาชุดเดียวสำหรับ dropdown จึงยังไม่ได้เพิ่ม pagination หรือ server-side search
- หากมีหลักสูตรเดิมที่ถูกปิดใช้งานไปแล้ว แต่ record อ้างอิงอยู่ ระบบจะยังแสดงค่าที่เคยบันทึกได้ใน edit mode ผ่าน option ที่เติมเข้ามาชั่วคราว