1.8 KiB
1.8 KiB
Training Type Review
Root Cause
- The form uses TanStack Form, not React Hook Form.
trainingTypein create mode was initialized asundefined.- The field-level blur validator had already been improved, but the submit-level Zod schema still used
z.enum(...). - When submit validation ran with an unset value, Zod could still produce a raw type error path like
expected string, received undefinedinstead of the intended Thai message.
Files Changed
src/features/training-records/schemas/training-record.tssrc/features/training-records/components/training-record-form.tsx
Fixed Code Summary
- Changed
trainingTypeform default fromundefinedto""in create mode. - Kept edit mode bound to the stored UI value.
- Updated the
Selectbinding to passundefinedto Radix only for display when the current form value is empty. - Replaced submit-level
z.enum(...)validation with string-based validation plus whitelist refinement so the message always stays:กรุณาเลือกประเภทการอบรม
- Kept the current app enum contract intact:
INTERNAL_TRAININGEXTERNAL_TRAININGONLINE_COURSEOJT
Regression Checklist
- Create mode: open new training record form and submit without selecting training type.
- Create mode: select each training type option and verify no raw Zod error appears.
- Edit mode: open an existing record and confirm the saved type renders correctly in the select.
- Edit mode: change the type and submit successfully.
- Validation after submit: confirm the Thai message appears instead of
Invalid inputorexpected string, received undefined. - Table/listing: verify training type badges still render correctly in Training Records and review pages.
- Server normalization: verify create/update payloads still map correctly to legacy DB values.