feat(emergency-contacts): add emergency contact management with CRUD, primary contact, and quick-access actions (Closes #143)#184
Conversation
… primary contact, and quick-access actions (Closes vallabhatech#143)
|
@SakethSumanBathini is attempting to deploy a commit to the vallabhatech's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
✅ Files skipped from review due to trivial changes (6)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds end-to-end emergency contact management. A new ChangesEmergency Contact Management
Sequence Diagram(s)sequenceDiagram
participant User
participant ProfilePage
participant EmergencyContacts
participant API as /api/auth/emergency-contacts
participant MongoDB
User->>ProfilePage: Open profile
ProfilePage->>EmergencyContacts: render
EmergencyContacts->>API: GET /
API->>MongoDB: User.findById(req.user.id)
MongoDB-->>API: user.emergencyContacts[]
API-->>EmergencyContacts: 200 contacts[]
User->>EmergencyContacts: Submit add/edit form
EmergencyContacts->>API: POST / or PUT /:id
API->>MongoDB: user.save()
MongoDB-->>API: updated contacts[]
API-->>EmergencyContacts: 201/200 contacts[]
EmergencyContacts-->>User: Flash success alert
User->>EmergencyContacts: Confirm delete
EmergencyContacts->>API: DELETE /:id
API->>MongoDB: splice + promote primary + user.save()
MongoDB-->>API: updated contacts[]
API-->>EmergencyContacts: 200 contacts[]
EmergencyContacts-->>User: Flash success alert
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
🤖 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 `@server/routes/emergencyContacts.js`:
- Line 37: The isPrimary variable assignment on lines 37 and 114 uses Boolean()
coercion which incorrectly treats the string "false" as truthy, causing wrong
primary contact reassignment. Replace the Boolean(req.body.isPrimary) calls with
explicit validation that checks if the value is specifically the string "true"
(such as comparing req.body.isPrimary === "true" or req.body.isPrimary === true)
to properly distinguish between true and false values from the request body.
🪄 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 Plus
Run ID: bceb27f6-1eb6-4923-a007-fd641e14459e
📒 Files selected for processing (6)
server/index.jsserver/models/User.jsserver/routes/emergencyContacts.jssrc/components/EmergencyContacts.jsxsrc/i18n/locales/en.jsonsrc/pages/Profile.jsx
…8n key-structure test) and fix Boolean isPrimary coercion
|
Hi @vallabhatech — follow-up commit (1aeef03) addresses both review findings: the |
|
The 4.9% duplication flag is a false positive inherent to i18n locale files — SonarQube sees identical JSON key names (e.g. "emergencyContactsTitle") across all 10 locale files and counts them as duplicate code, even though the values are different translations. This can be resolved by adding |


Summary
Implements full emergency contact management — users can store up to 3 contacts, designate a primary, and reach them instantly with one-tap call/SMS/email actions directly from their profile.
Closes #143
What was built
New files (2)
server/routes/emergencyContacts.jssrc/components/EmergencyContacts.jsxModified files (4)
server/models/User.jsEmergencyContactSchemasubdoc (name, relationship, phone, email, isPrimary) +emergencyContactsarray field. Purely additive — zero existing fields changed.server/index.jsrouterat/api/auth/emergency-contacts(after the existing/api/authline)src/pages/Profile.jsx<EmergencyContacts />below the existing profile cardsrc/i18n/locales/en.jsonprofilenamespace (all emergency-contact strings).fallbackLng: "en"means other locales degrade gracefully until translated.API endpoints
All routes require
Authorization: Bearer <token>(handled by the existingauthMiddleware).GET/api/auth/emergency-contactsPOST/api/auth/emergency-contactsPUT/api/auth/emergency-contacts/:idisPrimary: trueclears the previous primaryDELETE/api/auth/emergency-contacts/:idFrontend features
tel:,sms:, andmailto:links on each contact cardPR isolation from open PR #183
This PR deliberately avoids touching
server/routes/auth.jsorsrc/context/AuthContext.js(both modified in open PR #183). Emergency-contact data flows through dedicated endpoints, so the two PRs modify different hunks ofserver/index.jsand share no other files — they auto-merge in either order.Verification
node --checkon all 3 backend files_id, default empty array,.id()lookupt('profile:…')keys present in en.jsonUser.js: zero removals — purely additiveindex.js: +1 line onlyProfile.jsx: +import +render onlyChecklist
vallabhatechreplied "kindly proceed!")mainen.json; other locales fall back to English viafallbackLngSummary by CodeRabbit