#310 Enable changing tournament competitor count#311
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis change refactors the tournament form schema from a static export to a factory function that accepts runtime configuration. The schema now derives validation rules based on the current competitor count, enforcing that 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/TournamentForm/components/CompetitorFields.tsx`:
- Line 92: The FormField for maxCompetitors is incorrectly disabled for 'draft'
and 'published' instead of only when archived; update the disabled predicate for
the FormField named "maxCompetitors" (component using getCompetitorLabel and the
status variable) so the field is disabled only when status indicates archived
(e.g., disabled={status === 'archived'} or
disabled={['archived'].includes(status)}), ensuring it's editable while not
archived.
In `@src/components/TournamentForm/TournamentForm.schema.ts`:
- Around line 103-107: The validation message uses maxCompetitors to pick the
noun but should use the tournament mode; update the ctx.addIssue message
construction so it selects 'teams' vs 'players' based on the tournament mode
flag (e.g., a team boolean or mode on the config) rather than
data.maxCompetitors. Locate the block around data.maxCompetitors,
config.competitorCount and ctx.addIssue and compute a label like const
entityLabel = config.isTeamTournament ? 'teams' : 'players' (or use the existing
mode field on config), then interpolate entityLabel into the message.
In `@src/components/TournamentForm/TournamentForm.tsx`:
- Around line 66-68: The validation currently forces competitorCount to 0 when
tournamentCompetitors is unavailable which can incorrectly bypass the "cannot go
below existing competitors" rule; instead, change the call that builds
validation data to avoid the `?? 0` fallback — pass competitorCount as undefined
or omit it when `tournamentCompetitors` is nullish so
`validateForm(createSchema(...), formData, form.setError)` receives either the
real length (`tournamentCompetitors?.length`) or no competitorCount at all;
update the invocation around validateForm/createSchema (and adjust createSchema
if it expects optional competitorCount) so validation waits for actual
competitor data rather than assuming 0.
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
src/components/TournamentForm/TournamentForm.schema.tssrc/components/TournamentForm/TournamentForm.tsxsrc/components/TournamentForm/components/CompetitorFields.tsx
| </FormField> | ||
| <div className={styles.Stackable}> | ||
| <FormField name="maxCompetitors" label={`Total ${getCompetitorLabel()}`} disabled={disableFields}> | ||
| <FormField name="maxCompetitors" label={`Total ${getCompetitorLabel()}`} disabled={['draft', 'published'].includes(status)}> |
There was a problem hiding this comment.
maxCompetitors status gating is inverted for the requirement.
Line 92 currently disables edits in draft/published and allows edits in archived. That contradicts the requirement (“editable while not archived”).
Proposed fix
- <FormField name="maxCompetitors" label={`Total ${getCompetitorLabel()}`} disabled={['draft', 'published'].includes(status)}>
+ <FormField name="maxCompetitors" label={`Total ${getCompetitorLabel()}`} disabled={status === 'archived'}>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/components/TournamentForm/components/CompetitorFields.tsx` at line 92,
The FormField for maxCompetitors is incorrectly disabled for 'draft' and
'published' instead of only when archived; update the disabled predicate for the
FormField named "maxCompetitors" (component using getCompetitorLabel and the
status variable) so the field is disabled only when status indicates archived
(e.g., disabled={status === 'archived'} or
disabled={['archived'].includes(status)}), ensuring it's editable while not
archived.
| if (data.maxCompetitors < config.competitorCount) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| message: `Can not set tournament size to ${data.maxCompetitors} when there are already ${config.competitorCount} ${data.maxCompetitors > 1 ? 'teams' : 'players'} registered.`, | ||
| path: ['maxCompetitors'], |
There was a problem hiding this comment.
Validation message uses the wrong entity label in solo events.
Line 106 picks 'teams'/'players' from maxCompetitors, not from tournament mode. For non-team tournaments this can show the wrong noun.
Proposed fix
- message: `Can not set tournament size to ${data.maxCompetitors} when there are already ${config.competitorCount} ${data.maxCompetitors > 1 ? 'teams' : 'players'} registered.`,
+ message: `Can not set tournament size to ${data.maxCompetitors} when there are already ${config.competitorCount} ${data.competitorSize > 1 ? 'teams' : 'players'} registered.`,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/components/TournamentForm/TournamentForm.schema.ts` around lines 103 -
107, The validation message uses maxCompetitors to pick the noun but should use
the tournament mode; update the ctx.addIssue message construction so it selects
'teams' vs 'players' based on the tournament mode flag (e.g., a team boolean or
mode on the config) rather than data.maxCompetitors. Locate the block around
data.maxCompetitors, config.competitorCount and ctx.addIssue and compute a label
like const entityLabel = config.isTeamTournament ? 'teams' : 'players' (or use
the existing mode field on config), then interpolate entityLabel into the
message.
Resolves: #310
Summary by CodeRabbit
New Features
Improvements