Skip to content

[POLY-91] Add required field indicators and validation to listing creation#104

Merged
jaydonkc merged 5 commits intodevfrom
feature/POLY-91-listing-form-validation
Apr 21, 2026
Merged

[POLY-91] Add required field indicators and validation to listing creation#104
jaydonkc merged 5 commits intodevfrom
feature/POLY-91-listing-form-validation

Conversation

@cole-hackman
Copy link
Copy Markdown
Collaborator

@cole-hackman cole-hackman commented Apr 19, 2026

Summary

Improves the Create Listing form with visible required field indicators and inline validation so users know exactly what needs to be fixed before submitting.

Linear: POLY-91

Changes

frontend/app/listings/new.tsx

  • Added red asterisk (*) indicators on all required field labels (Photos, Title, Description, Price)
  • Added inline error messages below each field when validation fails
  • Added error border styling on invalid inputs (red border)
  • Replaced alert-based validation with field-level error state
  • Errors clear automatically as the user types/corrects the field
  • Added a summary error banner above the submit button when there are validation errors
  • Form submission is blocked until all required fields are valid
  • Category and Condition have defaults so they don't need required indicators

Validation rules:

  • Title: required, 5–100 characters
  • Description: required
  • Price: required, must be a valid non-negative number
  • Photos: at least 1, maximum 8

Testing

  • Manual: submit empty form → all required fields show inline errors, no alert popup
  • Manual: fix one field → that field's error clears immediately
  • Manual: fix all fields → form submits successfully
  • Works on both web and mobile layouts
  • 151 tests pass, lint clean

Created with Kiro

Summary by CodeRabbit

  • New Features

    • Form validation for new listings with real-time feedback and inline error messages.
    • Enforced field requirements: title (5–100 characters), non-empty description, valid non-negative price, and 1–8 images.
  • Tests

    • Added validation test suite verifying field validation behavior.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 19, 2026

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

Project Deployment Actions Updated (UTC)
poly-buys Ready Ready Preview, Comment Apr 21, 2026 3:21am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

Warning

Rate limit exceeded

@jaydonkc has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 2 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 46 minutes and 2 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6159743c-b55d-42ea-83ca-a881013cbac4

📥 Commits

Reviewing files that changed from the base of the PR and between de7b945 and fefbcd9.

📒 Files selected for processing (2)
  • frontend/app/listings/__tests__/newListingValidation.test.ts
  • frontend/app/listings/new.tsx
📝 Walkthrough

Walkthrough

The changes introduce form field validation for listings, adding a validation module with field-specific validators and error management utilities, integrating this into the form component with inline feedback UI and preventing submission until all required fields pass validation.

Changes

Cohort / File(s) Summary
Validation Module
frontend/app/listings/newListingValidation.ts
New validation module exporting FieldErrors type and validators for title (5–100 chars), description, price (non-negative number), and images (1–8). Includes utility functions hasFieldErrors, upsertFieldError, and validateListingFields for managing validation state.
Form Component Integration
frontend/app/listings/new.tsx
Updated listing form to add validation state (fieldErrors, hasAttemptedSubmit), controlled change handlers for each field that incrementally recompute errors, and reworked onSubmit to validate before submission. Added inline validation UI: RequiredLabel, FieldError components, conditional error styling, and form-level error banner.
Validation Tests
frontend/app/listings/__tests__/newListingValidation.test.ts
New test suite verifying validator functions handle empty/whitespace inputs, valid trimmed inputs, and invalid inputs correctly. Tests upsertFieldError removes fields by setting undefined and hasFieldErrors accurately reports error state.

Sequence Diagram

sequenceDiagram
    participant User
    participant Form as Form Component
    participant Handler as Change Handler
    participant Validator as Validation Module
    participant State as Component State
    participant UI as Rendered Output

    User->>Form: Enters/Changes Field Value
    Form->>Handler: Triggers onChange Event
    Handler->>State: Updates Field Value
    Handler->>Validator: Calls Validator for Field
    Validator->>Handler: Returns Error (if any)
    Handler->>State: Updates fieldErrors via upsertFieldError
    State->>UI: Re-renders with Error/Success State
    UI->>User: Displays Inline Error or Valid Indicator
    
    User->>Form: Submits Form
    Form->>Validator: Calls validateListingFields
    Validator->>Form: Returns All Field Errors
    Form->>State: Stores fieldErrors & hasAttemptedSubmit
    
    alt Validation Fails
        State->>UI: Displays Form-Level Error Banner
        UI->>User: Prevents Submission
    else Validation Passes
        Form->>Form: Proceeds with Create/Update Logic
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested Reviewers

  • SamanSP1386

Poem

🐰 Hop through fields with validation cheer,
Form errors now crystal clear!
Each input checked with careful might,
The listing form gets it just right! ✨🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding required field indicators and validation to the listing creation form.
Description check ✅ Passed The description includes a summary, detailed changes, validation rules, and testing notes, but is missing the structured sections (Linked Issues, How to Test checklist, Screenshots) from the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/POLY-91-listing-form-validation

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.

Copy link
Copy Markdown
Contributor

@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: 1

🧹 Nitpick comments (2)
frontend/app/listings/__tests__/newListingValidation.test.ts (1)

11-65: Tests are solid; consider adding boundary coverage.

The suite covers the happy path and the key upsertFieldError removal semantics cleanly. Consider adding assertions for the other documented bounds that aren't exercised today:

  • validateTitle with a 101+ char string → 'Title must be 100 characters or less.'
  • validateImages with a 9+ entry array → 'Maximum 8 photos allowed.'

These branches are implemented but currently untested, so regressions (e.g., flipping </>) would slip through.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/listings/__tests__/newListingValidation.test.ts` around lines 11
- 65, Add two boundary tests in the same test suite to cover the upper limits:
call validateTitle with a 101-character string and assert it returns 'Title must
be 100 characters or less.'; call validateImages with an array of 9 entries
(e.g., nine distinct strings) and assert it returns 'Maximum 8 photos allowed.'
Place these as new it(...) cases alongside existing tests so validateTitle and
validateImages branches for the 100-char and 8-photo limits are exercised.
frontend/app/listings/new.tsx (1)

163-198: Minor: setHasAttemptedSubmit(true) fires before the profile/uploads guards.

Once onSubmit sets hasAttemptedSubmit (Line 168) and then returns early because profile is still loading or uploads are pending (Lines 170–186), every subsequent keystroke will start surfacing inline errors even though the user never actually failed validation. Consider moving setHasAttemptedSubmit(true) down to just before validateListingFields so the "attempted" state only latches when a real validation pass was made.

♻️ Suggested move
   async function onSubmit() {
     if (submittingRef.current) {
       return;
     }
 
-    setHasAttemptedSubmit(true);
-
     if (profile === undefined) { ... return; }
     if (profile === null)      { ... return; }
     if (hasPendingUploads)     { ... return; }
 
+    setHasAttemptedSubmit(true);
     const errors = validateListingFields({ title, description, price, images });
     setFieldErrors(errors);
-    if (Object.keys(errors).length > 0) {
+    if (hasFieldErrors(errors)) {
       return;
     }

Also swapping Object.keys(errors).length > 0 for hasFieldErrors(errors) keeps the gate consistent with the module's public API.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/listings/new.tsx` around lines 163 - 198, Move the
setHasAttemptedSubmit(true) call in onSubmit so it runs only after passing the
early guards (profile/loading and hasPendingUploads) and immediately before
calling validateListingFields; this ensures hasAttemptedSubmit only flips when a
real validation attempt occurs. Update the post-validation gate to use the
public helper hasFieldErrors(errors) instead of Object.keys(errors).length > 0
and continue to call setFieldErrors(errors) and bail out if
hasFieldErrors(errors) returns true. Ensure references are to onSubmit,
setHasAttemptedSubmit, validateListingFields, setFieldErrors, hasFieldErrors,
profile, and hasPendingUploads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/app/listings/new.tsx`:
- Around line 153-161: In handleImagesChange, don't call setFieldErrors from
inside the setImages updater; compute nextImages first (using the incoming
newImages or invoking it with prevImages), then call setImages(nextImages) and,
if hasAttemptedSubmit, call setFieldErrors(prev => upsertFieldError(prev,
'images', validateImages(nextImages))). This keeps the setImages updater pure
and matches the pattern used in handlePriceChange; reference functions/idents:
handleImagesChange, setImages, setFieldErrors, upsertFieldError, validateImages,
hasAttemptedSubmit.

---

Nitpick comments:
In `@frontend/app/listings/__tests__/newListingValidation.test.ts`:
- Around line 11-65: Add two boundary tests in the same test suite to cover the
upper limits: call validateTitle with a 101-character string and assert it
returns 'Title must be 100 characters or less.'; call validateImages with an
array of 9 entries (e.g., nine distinct strings) and assert it returns 'Maximum
8 photos allowed.' Place these as new it(...) cases alongside existing tests so
validateTitle and validateImages branches for the 100-char and 8-photo limits
are exercised.

In `@frontend/app/listings/new.tsx`:
- Around line 163-198: Move the setHasAttemptedSubmit(true) call in onSubmit so
it runs only after passing the early guards (profile/loading and
hasPendingUploads) and immediately before calling validateListingFields; this
ensures hasAttemptedSubmit only flips when a real validation attempt occurs.
Update the post-validation gate to use the public helper hasFieldErrors(errors)
instead of Object.keys(errors).length > 0 and continue to call
setFieldErrors(errors) and bail out if hasFieldErrors(errors) returns true.
Ensure references are to onSubmit, setHasAttemptedSubmit, validateListingFields,
setFieldErrors, hasFieldErrors, profile, and hasPendingUploads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f100d84e-6c53-4d10-9761-e07778c38afe

📥 Commits

Reviewing files that changed from the base of the PR and between 8602ce7 and de7b945.

📒 Files selected for processing (3)
  • frontend/app/listings/__tests__/newListingValidation.test.ts
  • frontend/app/listings/new.tsx
  • frontend/app/listings/newListingValidation.ts

Comment thread frontend/app/listings/new.tsx
@jaydonkc jaydonkc merged commit b2def25 into dev Apr 21, 2026
5 checks passed
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.

2 participants