minipower-frontend-form-react
Form theo kit @platform/core — Zod schema + *FormDefaultValues + map entity→form ở validation/, hook use{Feature}Form (react-hook-form + zodResolver, mode onChange), component form chỉ có trường nhận register/control/errors, Controller cho FieldSelect/SearchableSelect/KitDatePicker/ToggleSwitch/PasswordInput, submit qua handleAction + notify. Dùng khi thêm form tạo/sửa, thêm validation hoặc trường bắt buộc, chọn ngày / chọn bản ghi liên kết, form trong dialog, hoặc form sửa không nạp dữ liệu cũ.
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 7
- Forks
- 0
01 前言 Front Matter
- name
- minipower-frontend-form-react
- metadata
- { "workflow": "github" }
- description
- Form theo kit @platform/core — Zod schema + *FormDefaultValues + map entity→form ở validation/, hook use{Feature}Form (react-hook-form + zodResolver, mode onChange), component form chỉ có trường nhận register/control/errors, Controller cho FieldSelect/SearchableSelect/KitDatePicker/ToggleSwitch/PasswordInput, submit qua handleAction + notify. Dùng khi thêm form tạo/sửa, thêm validation hoặc trường bắt buộc, chọn ngày / chọn bản ghi liên kết, form trong dialog, hoặc form sửa không nạp dữ liệu cũ.
02 资源文件 9
- 参考文档README.md1.7 KB
- 参考文档reference/controls.md5.3 KB
- 其他templates/components/{Feature}Form/{Feature}Form.tsx3.9 KB
- 脚本templates/components/{Feature}Form/index.ts106 B
- 脚本templates/hooks/index.ts169 B
- 脚本templates/hooks/use{Feature}Form.ts754 B
- 脚本templates/validation/{feature}.ts1.3 KB
- 脚本templates/validation/index.ts215 B
- 参考文档workflows/add-form.md4.6 KB
03 SKILL.md 正文
Form (@platform/core) — Orchestrator
Skill sở hữu ba mảnh của một form: schema (validation/) · hook (hooks/use{Feature}Form) · component trường (components/{Feature}Form). Ai submit, gọi API nào, đi đâu sau khi lưu — thuộc page / dialog (crud).
Hướng dẫn người: README.md.
Khi nào dùng workflow nào
| Tình huống | Workflow |
|---|---|
| Thêm form mới hoặc thêm trường vào form có sẵn | workflows/add-form.md |
| Trường là select / chọn bản ghi / ngày / giờ / bật-tắt / mật khẩu | reference/controls.md |
Luồng một form
validation/{feature}.ts schema Zod · {Feature}FormData = z.infer · {feature}FormDefaultValues · to{Feature}FormValues(entity)
│
hooks/use{Feature}Form useForm({ resolver: zodResolver(schema), mode: 'onChange', defaultValues })
│ register · control · errors
components/{Feature}Form chỉ trường + lỗi — KHÔNG submit, KHÔNG gọi API
│
page / dialog handleSubmit(data ⇒ handleAction({ defaultSubmit: map form → payload → call* }))
Quy tắc cốt lõi
- Ràng buộc khớp backend.
min/max/bắt buộc lấy từ DOC-12 / DOC-11 — form cho qua mà API trả 400 là lỗi của schema. Thiếu số liệu ⇒ hỏi, đừng tự đặt. - Message lỗi tiếng Việt ngay trong schema — hiện thẳng dưới trường, không dịch lại ở component.
- Kiểu form ≠ kiểu payload. Map tường minh trong
defaultSubmit(sửa thường không gửistatus); map ngược bằngto{Feature}FormValues. - Ô tuỳ chọn trống →
null(setValueAs) — backend .NET nhậnnull, không nhận''. - Input gốc dùng
register; control khác bọcController— đúng giá trị dây của control (reference/controls.md). Ngày không giờ giữ chuỗi'YYYY-MM-DD'. - Sửa: nạp dữ liệu rồi
reset.defaultValuescủauseFormchỉ đọc lần đầu — dữ liệu về sau phảireset({ ...defaults, ...values }). Tham chiếudefaultValuestruyền vào page phải ổn định, không thì form reset mỗi lần render. - Form trong dialog dùng MỘT instance —
reset(defaults)khi mở tạo,reset(to{Feature}FormValues(item))khi mở sửa. - Submit:
<form noValidate>, nútdisabled={isSubmitting}, lỗi API ⇒notify.error(getErrorMessage(error, …)).
Templates
Placeholder: architecture § Placeholder.
| Template | Đích |
|---|---|
| templates/validation/{feature}.ts | src/features/{feature}/validation/{feature}.ts |
| templates/validation/index.ts | validation/index.ts |
| templates/hooks/use{Feature}Form.ts | hooks/use{Feature}Form.ts |
| templates/hooks/index.ts | hooks/index.ts |
| templates/components/{Feature}Form/ | components/{Feature}Form/ |
Class trường (fieldInputClass…) từ components/fieldStyles.ts — template của convention.
Tham chiếu
- reference/controls.md — bảng control → giá trị dây → Zod → cách gắn, kèm đoạn mẫu. Không load mặc định.
Output bắt buộc
- Schema, kiểu, mặc định, mapper ở
validation/; component form không importservices/(lint R6) npm run typecheck+npm run lintxanh- Chạy thật: submit form trống hiện lỗi dưới từng trường bắt buộc; mở form sửa thấy dữ liệu cũ; lưu xong có toast
- Code theo minipower-frontend-convention-react; file đặt đúng folder theo minipower-frontend-architecture-react
Liên quan
- Page / dialog sở hữu submit: minipower-frontend-crud-react
- Kiểu payload theo DOC-12: minipower-frontend-api-react
04 同仓库更多 Skills
minipower-vcs-gitlab
Tra GitLab (search, issue, pipeline, MR), soạn MR/comment, tạo MR và commit/push sau L2. Dùng khi merge request, GitLab MCP, code_provider gitlab — không scaffold .NET, không force-push.
minipower-toolbox-skill-author
Viết và soát skill lá-rời Minipower (minipower-{module}-{capability}) — chọn module bằng 3 câu hỏi ADR-022, dựng cây SKILL.md/README.md/workflows/providers, đặt description kích hoạt được, cập nhật hub và test canh. Hỏi người xác nhận trước mọi quyết định, không tự chốt. Dùng khi tạo skill mới, thêm provider/pattern/workflow, mở module mới, hoặc soát skill có sẵn lệch chuẩn.
minipower-tasks-lark
Đọc, lọc, tìm, soạn nháp và ghi task Lark (tasklist / task) theo L1–L3. Dùng khi việc trên Lark, sprint, tasklist, "tìm task", "tạo task", tasks_provider lark — không dùng cho tin nhắn nhóm hay wiki.
minipower-support-registry
Rà registry DOC theo project_mode, nhắc owner thiếu ID hoặc chỗ lưu sai. Dùng khi doc-registry, thiếu DOC, rà soát tiêu chuẩn — không tự sửa FR, không init.
minipower-support-publish
暂无简介
minipower-router
Phân loại intent Minipower rồi gợi ý đúng một pack nghề hoặc kênh. Dùng khi làm gì tiếp, chọn skill, dispatcher, không biết mở pack nào — không tự gọi MCP L3, không spawn agent.