Skip to content

#310 Enable changing tournament competitor count#311

Merged
ianpaschal merged 2 commits intomainfrom
310-enable-changing-tournament-competitor-count
Mar 2, 2026
Merged

#310 Enable changing tournament competitor count#311
ianpaschal merged 2 commits intomainfrom
310-enable-changing-tournament-competitor-count

Conversation

@ianpaschal
Copy link
Owner

@ianpaschal ianpaschal commented Mar 2, 2026

Resolves: #310


Summary by CodeRabbit

  • New Features

    • Tournament form validation now dynamically enforces competitor limits based on actual tournament competitor count.
  • Improvements

    • Maximum competitor field is now locked during draft and published states, and editable during active and archived states for better control.

@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
combat-command Ready Ready Preview, Comment Mar 2, 2026 10:02am

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This 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 maxCompetitors cannot be lower than existing competitors. The component is updated to fetch tournament competitors and pass their count to the schema factory. Additionally, the disabled state of the maxCompetitors field is modified to only restrict editing for draft and published tournament statuses, allowing edits in other states like active and archived.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main change: enabling the ability to change tournament competitor count.
Description check ✅ Passed The PR description follows the required template with the issue reference, though it provides minimal additional context beyond the template.
Linked Issues check ✅ Passed The code changes successfully implement both functional requirements: the schema now supports runtime configuration of competitorCount, includes validation preventing maxCompetitors from being set below current competitor count, and the UI enables editing except when archived.
Out of Scope Changes check ✅ Passed All changes are directly related to enabling competitor count adjustment. The schema factory, validation logic, hook addition, and UI disable logic all support the stated objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 310-enable-changing-tournament-competitor-count

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ianpaschal ianpaschal marked this pull request as ready for review March 2, 2026 09:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f064631 and 9630ab9.

📒 Files selected for processing (3)
  • src/components/TournamentForm/TournamentForm.schema.ts
  • src/components/TournamentForm/TournamentForm.tsx
  • src/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)}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

Comment on lines +103 to +107
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'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@ianpaschal ianpaschal merged commit bc8b6fd into main Mar 2, 2026
3 checks passed
@ianpaschal ianpaschal deleted the 310-enable-changing-tournament-competitor-count branch March 2, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant