82 lines
4.8 KiB
Markdown
82 lines
4.8 KiB
Markdown
# Course Selection Review
|
|
|
|
## Summary
|
|
|
|
ปรับฟอร์มบันทึกประวัติการอบรมของพนักงานจากช่องกรอกชื่อหลักสูตรแบบข้อความธรรมดา เป็น searchable course combobox ที่รองรับทั้งการเลือกจาก Course Master และการกรอกชื่อหลักสูตรเอง โดยยังคงบันทึก `courseName` เดิมไว้ และเพิ่มการผูก `courseId` เมื่อเลือกจากหลักสูตรกลาง
|
|
|
|
## Files Changed
|
|
|
|
- `src/app/api/courses/route.ts`
|
|
- `src/app/api/training-records/route.ts`
|
|
- `src/app/api/training-records/[id]/route.ts`
|
|
- `src/features/training-records/api/types.ts`
|
|
- `src/features/training-records/api/service.ts`
|
|
- `src/features/training-records/api/queries.ts`
|
|
- `src/features/training-records/components/training-record-course-combobox.tsx`
|
|
- `src/features/training-records/components/training-record-form.tsx`
|
|
- `src/features/training-records/schemas/training-record.ts`
|
|
- `src/features/training-records/server/training-record-data.ts`
|
|
|
|
## UI Changes
|
|
|
|
- เปลี่ยน field หลักสูตรเป็น combobox แบบค้นหาได้
|
|
- แสดงรายการด้วยรูปแบบ `courseCode - courseName`
|
|
- เพิ่มตัวเลือก `อื่น ๆ / กรอกชื่อหลักสูตรเอง`
|
|
- เมื่อเลือก custom course จะแสดง input สำหรับกรอกชื่อหลักสูตรเอง
|
|
- layout ยังใช้งานได้บน mobile และ desktop
|
|
|
|
## Course Selection Behavior
|
|
|
|
- ผู้ใช้ค้นหาหลักสูตรจาก Course Master ได้ด้วยชื่อหลักสูตรหรือรหัสหลักสูตร
|
|
- แสดงเฉพาะหลักสูตรที่ active
|
|
- เมื่อเลือกหลักสูตรจาก Course Master:
|
|
- บันทึก `courseId`
|
|
- กำหนด `courseName` ตามชื่อหลักสูตรจาก master
|
|
- auto-fill `organizer` ถ้ามี
|
|
- auto-fill `hours` จาก `standardHours` ถ้ามี
|
|
|
|
## Custom Course Behavior
|
|
|
|
- ผู้ใช้สามารถเลือก `อื่น ๆ / กรอกชื่อหลักสูตรเอง`
|
|
- ในกรณีนี้:
|
|
- `courseId = null`
|
|
- ต้องกรอกชื่อหลักสูตรเอง
|
|
- ระบบยังบันทึก `courseName` ตามค่าที่กรอก
|
|
|
|
## Validation Rules
|
|
|
|
- ต้องเลือกหลักสูตรจาก master หรือกรอกชื่อหลักสูตรเอง
|
|
- ถ้าเลือก custom course จะต้องกรอกชื่อหลักสูตร
|
|
- `hours` ต้องมากกว่า 0
|
|
- `courseName` จะไม่ถูกปล่อยให้ว่างก่อน submit
|
|
|
|
## Database Behavior
|
|
|
|
- ถ้าเลือกจาก Course Master:
|
|
- บันทึก `courseId`
|
|
- บันทึก `courseName` จากข้อมูลหลักสูตรกลาง
|
|
- ถ้าเป็น custom course:
|
|
- บันทึก `courseId = null`
|
|
- บันทึก `courseName` จากข้อความที่ผู้ใช้กรอก
|
|
- ไม่มีการลบ field `courseName` เดิม
|
|
|
|
## Manual Test Checklist
|
|
|
|
- Employee can search course from Course Master.
|
|
- Employee can select course from Course Master.
|
|
- Selected course fills course name.
|
|
- Selected course fills provider if available.
|
|
- Selected course fills default hours if available.
|
|
- Employee can choose custom course.
|
|
- Custom course name is required.
|
|
- Saving master course stores courseId.
|
|
- Saving custom course stores courseId as null.
|
|
- HRD review still displays course name correctly.
|
|
- Duplicate warning still works.
|
|
- Mobile layout works.
|
|
|
|
## Known Limitations
|
|
|
|
- งานนี้ใช้ route `/api/courses` เดิมในการอ่าน course list และเปิดสิทธิ์อ่านให้ผู้ใช้ในองค์กร แต่ยังคงจำกัดการสร้างหลักสูตรไว้ที่ HRD
|
|
- ถ้าหลักสูตรเดิมของ record ถูกปิดใช้งานภายหลัง ระบบยังคงแสดงชื่อหลักสูตรเดิมได้ แต่ตัวเลือกค้นหาใหม่จะแสดงเฉพาะหลักสูตร active
|