Files
alla-tms/docs/public-training-attachment-requirement-report.md
2026-07-16 09:53:14 +07:00

82 lines
3.4 KiB
Markdown

# Public Training Attachment Requirement Report
## Summary
Implemented the public training attachment requirement in the shared training record form flow so create and edit screens now:
- show a dynamic red notice when the selected training type is `EXTERNAL_TRAINING`
- block submit when public training has no attachment
- allow unlimited attachment selection in the UI while keeping the existing 10 MB per-file rule and file-type rule
## Files Changed
- `src/features/training-records/components/training-record-form.tsx`
- `src/features/training-records/components/training-record-certificate-manager.tsx`
- `src/features/training-records/constants/certificate-upload.ts`
## Requirement Mapping
- Dynamic warning for Public Training:
Added conditional notice rendering in the shared training record form based on `EXTERNAL_TRAINING`.
- Upload section placement:
Notice is rendered directly in the upload section above the uploader.
- Required attachment validation:
Submit is blocked in the shared form when public training has no existing or pending attachment.
- Attachment rule:
Reused the existing PDF/JPG/JPEG/PNG and 10 MB per-file limits, and removed the previous UI file-count cap.
- Shared pattern:
Kept the existing TanStack Form + mutation + certificate upload flow and updated the shared form used by both create and edit routes.
## Implementation Details
- Added `certificate-upload.ts` as the shared source for:
- public training type constant
- public training warning/error messages
- accepted file types
- max file size
- uploader max file count behavior
- Updated `training-record-form.tsx` to:
- read existing certificate count for edit mode
- render a red notice when `trainingType === "EXTERNAL_TRAINING"`
- prevent submit if public training has neither existing attachments nor pending files
- clear the attachment error when attachments are added or the training type changes away from public training
- upload attachments before the record update in the specific edit case where public training would otherwise become attachment-less
- roll back newly created public training records if attachment upload fails after create
- Updated `training-record-certificate-manager.tsx` to reuse the same upload constants and remove the old `maxFiles={5}` limit.
## Validation Rules
- Public training requires at least one attachment before submit.
- Non-public training keeps the previous behavior and does not require attachments.
- Accepted file types remain:
- PDF
- JPG
- JPEG
- PNG
- Maximum size remains 10 MB per file.
## Testing Result
- Code path reviewed for:
- create flow (`trainingRecordId === "new"`)
- edit flow (`trainingRecordId !== "new"`)
- shared training record form
- existing certificate manager upload flow
- Automated verification pending:
- project lint
- build
- browser/manual interaction checks
## Impact Analysis
- No database schema changes.
- No training record API contract changes.
- No role or permission changes.
- Existing certificate upload storage flow is preserved.
- The change is scoped to training-record attachment UX and submit validation.
## Notes / Limitations
- The attachment requirement is enforced in the shared client form flow, which is the existing create/edit entry point for dashboard users.
- I kept the route-handler contract unchanged to avoid widening the feature scope and to stay aligned with the current two-step record-create then certificate-upload architecture.