Conversation
we make the zod schema representative, and handle checks logic in the component
There was a problem hiding this comment.
Pull request overview
Refactors character creation validation to rely more on Zod-driven parsing/errors, improving required-field handling and surfaced error messages during both submit and live (is_check) validation.
Changes:
- Move
createCharacterto Zod-parse first and convert Zod errors viazodToFormErrors. - Tighten schema constraints for required fields and SRD 5.2 background ability bonuses (cap per-ability bonus at +2).
- Add UI-side filtering to suppress empty-field errors during live (
is_check) validation and add/adjust related tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/services/createCharacter.ts | Refactors validation flow to parse with Zod first; updates schema requirements and SRD 5.2 bonus validation. |
| src/services/createCharacter.test.ts | Adds coverage for missing class messaging; updates SRD 5.2 bonus validation expectation. |
| src/lib/formErrors.ts | Enhances Zod issue flattening (nested union paths) and adds ignoreCheckEmptyErrors. |
| src/components/CharacterNew.tsx | Filters out empty-field errors during live validation using ignoreCheckEmptyErrors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/services/createCharacter.ts
Outdated
| @@ -27,11 +27,11 @@ import { addLevel } from "./addLevel" | |||
| */ | |||
| const BaseCharacterSchema = z.object({ | |||
| name: z.string().min(3, "Pick a better character name!").max(50, "That name is too long!"), | |||
There was a problem hiding this comment.
name validation no longer trims whitespace. As written, a value like " " (3+ spaces) passes z.string().min(3, ...) and will proceed to uniqueness + DB insert, whereas the previous logic rejected whitespace-only names via trim(). Consider applying .trim() in the Zod schema (or a refine) and using a required/empty message for the blank-after-trim case.
| name: z.string().min(3, "Pick a better character name!").max(50, "That name is too long!"), | |
| name: z | |
| .string() | |
| .trim() | |
| .min(1, "Character name is required") | |
| .min(3, "Pick a better character name!") | |
| .max(50, "That name is too long!"), |
3d759cc to
818d8d4
Compare
Refactor character creation for better error messages and to prevent missing fields.