Skip to content

Participant name and notes limits are typed twice, in the schemas and on the participant pages #705

Closed

Description

@richshaw

What happens

The limits on what a participant can type are literals in two places each:

  • Name, 100 characters. NameSchema in src/schemas/common.ts has .max(100), and NAME_INVALID in src/app/s/[slug]/name-message.ts types "Enter your name, up to 100 characters."
  • Notes, 500 characters. The create and update schemas in src/schemas/commitments.ts each have .max(500), and the Notes field in src/app/s/[slug]/participant-fields.tsx has maxLength={500}. The sign-up dialog and the edit page both use that field.
  • Quantity, 999. Typed twice inside src/schemas/commitments.ts, and nowhere on the client.

If someone changes a limit in the schema, the participant page's message and the textarea's maxLength are left saying the old number.

The organizer's New signup form (src/app/app/(chrome)/signups/new/page.tsx) has the same kind of copies. It types minLength={2}, maxLength={120} and maxLength={2000}, while src/schemas/signups.ts already has TITLE_MAX_LENGTH and DESCRIPTION_MAX_LENGTH, plus TITLE_MIN_LENGTH, which isn't exported.

Fix, in outline

  • A new limits module. Add src/lib/participant-limits.ts with no imports at all (like src/lib/magic-compose/limits.ts), holding NAME_MAX_LENGTH = 100, NOTES_MAX_LENGTH = 500 and QUANTITY_MAX = 999.
  • Use it everywhere. Use the constants in NameSchema, both commitment schemas, NAME_INVALID (as a template string) and the Notes field. Update src/schemas/common.test.ts's 100/101 boundary test to use the constant.
  • The New signup form. Export TITLE_MIN_LENGTH, then use it with TITLE_MAX_LENGTH and DESCRIPTION_MAX_LENGTH on the form. It's a server component, so it can import from @/schemas/signups at no cost.

Watch for

  • Keep zod out of the participant pages. name-message.ts and participant-fields.tsx reach 'use client' components on /s/[slug]. The constants must not live in src/schemas or anywhere that imports zod, or zod lands in those pages' JavaScript and budgets.json fails.
  • No behaviour change. Don't add a maxLength to the name inputs: that would change what participants see, so it's a separate decision.

Done when

  • Each of these limits is a number in exactly one place: name, notes, quantity, and title and description on the New signup form.
  • pnpm budgets after pnpm build shows /s/[slug] and /s/[slug]/c/[id] unchanged.
  • pnpm lint && pnpm typecheck && pnpm knip && pnpm test pass.

Found by the pipeline's refactor scout in src/schemas and src/app/s/[slug], at a65d5eb. Checked by locating every copy and each participant module's imports. https://claude.ai/code/session_016YZ9SVWAFTJiB4Z8TyLWNA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions