fix: add client-side validation for future birth dates in PetForm#252
Conversation
|
Warning Rate limit exceeded
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 24 minutes and 23 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPetForm component now validates that date-of-birth values are not in the future through client-side checks and Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 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 `@frontend/src/components/PetForm.jsx`:
- Around line 174-178: The error banner in PetForm.jsx rendering
{fieldErrors.general} contains an accidental "..." utility class; remove the
literal "..." and replace it with concrete Tailwind classes (e.g., padding, text
color/size, and spacing) so the banner is fully styled—update the JSX div that
checks fieldErrors.general to use classes like p-3 or px-4 py-3 plus text-sm
text-red-700 bg-red-50 border border-red-200 rounded-lg instead of "...".
- Around line 50-58: The current handler in PetForm.jsx assumes data.errors is
an array and calls data.errors.forEach(...), but the backend sends an object map
(e.g. { dateOfBirth: [...] }), causing a crash and skipping the field-level
fallback; update the logic in the PetForm.jsx error handling to detect whether
data.errors is an Array or an Object (use Array.isArray) and handle both shapes:
if array, keep the existing forEach logic mapping err.field/defaultMessage; if
object, iterate Object.entries(data.errors) and for each key (like
"dateOfBirth") pick the first message in the array or map specific keys to
errors.dob, otherwise set errors[key] to the first message; ensure you update
the same variables (data.errors, errors, errors.dob, dateOfBirth) so downstream
validation/display works.
- Line 15: The current const today uses toISOString() (UTC) which misaligns with
the HTML date input and validation; replace it with a local-date string
constructed from new Date() using getFullYear(), getMonth()+1, and getDate()
with zero-padding so today matches the user's local calendar, then use that same
local today value for the input max and the form validation check (the
comparison involving formData.dob) to ensure both the max attribute and the
client-side "dob > today" logic use the same local-date format.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d5ff9858-267b-4e5c-9390-87acdd7ccd9e
📒 Files selected for processing (1)
frontend/src/components/PetForm.jsx
Closes #224
DONE
max={today}på date-inputen så webbläsarens kalender spärrar framtida datumdateOfBirth→ fältfel i UI:tIngen backend-ändring
Befintlig
@PastOrPresent-validering iPetRequest.javaär oförändrad.Summary by CodeRabbit
Release Notes
New Features
Bug Fixes