72 form updates#87
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds server-side email availability check and duplicate error, normalizes emails (trim + lowercase) across client submit and server persistence, enforces transaction-time duplicate checks, integrates async client-side uniqueness validation and normalized confirmation comparison, and updates routing and localStorage handling. ChangesFamily Email Duplicate Detection and Normalization
Sequence Diagram(s)sequenceDiagram
participant Client
participant validateUniqueFamilyEmail
participant checkFamilyEmailAvailability
participant Firestore
Client->>validateUniqueFamilyEmail: onChange/onSubmit (email)
validateUniqueFamilyEmail->>checkFamilyEmailAvailability: POST normalized email
checkFamilyEmailAvailability->>checkFamilyEmailAvailability: normalize + validate input
checkFamilyEmailAvailability->>Firestore: query families where email == normalizedEmail
alt duplicate found
checkFamilyEmailAvailability-->>validateUniqueFamilyEmail: throw DUPLICATE_FAMILY_EMAIL_MESSAGE
validateUniqueFamilyEmail-->>Client: validator error (duplicate)
else available
checkFamilyEmailAvailability->>validateUniqueFamilyEmail: { available: true }
validateUniqueFamilyEmail-->>Client: validator passes
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/components/form/sections/GeneralInfo.tsx`:
- Around line 35-38: The catch block in GeneralInfo.tsx currently returns
error.message directly which can leak backend details; update the catch so it
only returns the raw DUPLICATE_FAMILY_EMAIL_MESSAGE when the caught error is an
Error AND its message exactly matches DUPLICATE_FAMILY_EMAIL_MESSAGE, otherwise
return a controlled generic validation message (e.g., "Unable to validate email
at this time") instead of error.message; change the logic around the existing
catch in the function handling family email validation to compare error.message
to DUPLICATE_FAMILY_EMAIL_MESSAGE and fallback to the safe generic string for
all other errors.
In `@app/src/server/functions/familyForm.ts`:
- Around line 97-107: The current non-transactional uniqueness check in
assertFamilyEmailAvailable allows races; move the uniqueness enforcement inside
the same database transaction that creates the family (the runTransaction block
that writes the family document with email: normalizedEmail) or implement an
atomic claim collection (e.g., create/claim a familyEmailClaims document keyed
by normalizedEmail inside runTransaction) so the transaction either
reads/creates the claim and then writes the family or fails if the claim exists;
update code paths that call assertFamilyEmailAvailable to instead perform the
check/claim within the transaction and remove the external pre-check to ensure
atomicity.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0e1f1dc4-0de3-46a8-818a-49de131ed08a
📒 Files selected for processing (3)
app/src/components/form/sections/GeneralInfo.tsxapp/src/hooks/mutations/useSubmitFamilyForm.tsapp/src/server/functions/familyForm.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
app/src/server/functions/familyForm.ts (1)
210-217:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftQuery-in-transaction still leaves a duplicate-email race.
This query only protects documents it actually reads. If the result is empty, two concurrent submissions can both observe “no family yet” and each create a different family with the same normalized email. Use a sentinel/claim document keyed by the normalized email (or the email itself as the document ID) and read/create that exact document inside the transaction.
In Cloud Firestore, if a transaction reads a query that currently returns no documents and then writes a new document that would match that query, can two concurrent transactions both commit? What do the official docs recommend for enforcing uniqueness?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/src/server/functions/familyForm.ts` around lines 210 - 217, The transaction currently queries db.families.where(...) which can still race; instead use a sentinel document keyed by the normalized email and read/create that exact document inside the transaction: in the runTransaction block replace the query-based check (existingFamily / db.families.where) with a transactional read of db.families.doc(normalizedEmail) (or a dedicated claims collection like familiesClaims.doc(normalizedEmail)), throw DUPLICATE_FAMILY_EMAIL_MESSAGE if that doc exists, and create the sentinel/doc as part of the same transaction before creating the family record so uniqueness is enforced atomically.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/components/form/sections/GeneralInfo.tsx`:
- Around line 19-44: Synchronous validators must use the same trim+lowercase
normalization as validateUniqueFamilyEmail to avoid false mismatches; update the
synchronous email validator to normalize the input (const normalized =
value?.trim().toLowerCase()) before empty and regex checks, and update the
emailConfirm comparison to compare normalized versions (normalize both email and
emailConfirm) so case-only or whitespace-only differences no longer cause
“invalid” or “Emails do not match” results; refer to validateUniqueFamilyEmail
and the email / emailConfirm validators (the comparison logic around lines
90-94) when making the changes.
---
Duplicate comments:
In `@app/src/server/functions/familyForm.ts`:
- Around line 210-217: The transaction currently queries db.families.where(...)
which can still race; instead use a sentinel document keyed by the normalized
email and read/create that exact document inside the transaction: in the
runTransaction block replace the query-based check (existingFamily /
db.families.where) with a transactional read of db.families.doc(normalizedEmail)
(or a dedicated claims collection like familiesClaims.doc(normalizedEmail)),
throw DUPLICATE_FAMILY_EMAIL_MESSAGE if that doc exists, and create the
sentinel/doc as part of the same transaction before creating the family record
so uniqueness is enforced atomically.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 720267a2-10f8-43b5-838e-ee1ea7ea5b09
📒 Files selected for processing (8)
app/src/components/form/sections/GeneralInfo.tsxapp/src/components/providers/FormProvider.tsxapp/src/hooks/mutations/useSubmitFamilyForm.tsapp/src/routeTree.gen.tsapp/src/routes/family/drive/$driveId/form.tsxapp/src/routes/family/drive/$driveId/form/$.tsxapp/src/routes/family/drive/$driveId/form/review.tsxapp/src/server/functions/familyForm.ts
✅ Files skipped from review due to trivial changes (2)
- app/src/routes/family/drive/$driveId/form/$.tsx
- app/src/routeTree.gen.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- app/src/hooks/mutations/useSubmitFamilyForm.ts
Pull Request
some form updates.
Description
Type of Change
Related Issues (put task name here from notion)
Screenshots (If it is a front end feature screenshot is required)
Additional Notes
Summary by CodeRabbit
New Features
Bug Fixes