-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Handle null gender values in user profiles #10614
Fix: Handle null gender values in user profiles #10614
Conversation
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant UF as UserForm
participant UE as useEffect
UF->>UE: Trigger form reset for edit mode
UE->>UF: Set formData.gender = userData.gender || undefined
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/components/Users/UserForm.tsx (1)
94-94
: Consider making gender optional in edit mode.Currently, gender is required in both create and edit modes. Since we're handling null gender values, consider making it optional in edit mode similar to other fields.
-gender: z.enum(GENDERS, { required_error: t("gender_is_required") }), +gender: isEditMode + ? z.enum(GENDERS).optional() + : z.enum(GENDERS, { required_error: t("gender_is_required") }),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/Users/UserForm.tsx
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/components/Users/UserForm.tsx (1)
Learnt from: rajku-dev
PR: ohcnetwork/care_fe#9887
File: src/components/Users/CreateUserForm.tsx:93-93
Timestamp: 2025-01-14T09:22:13.878Z
Learning: The suggestion to use GENDER_TYPES.map(g => g.id) for gender enum validation in CreateUserForm.tsx was incorrect and caused an error.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Test
🔇 Additional comments (2)
src/components/Users/UserForm.tsx (2)
148-148
: LGTM! The change improves null gender value handling.The change ensures that falsy gender values are explicitly set to
undefined
during form reset, which aligns with the form's validation schema.
36-37
:✅ Verification successful
Verify the difference between GENDER_TYPES and GENDERS.
The code imports both
GENDER_TYPES
(used in UI) andGENDERS
(used in validation). This could lead to inconsistencies if they're not synchronized.
🏁 Script executed:
#!/bin/bash # Search for the definitions of GENDER_TYPES and GENDERS echo "Searching for GENDER_TYPES definition:" rg "GENDER_TYPES.*=" -A 5 echo -e "\nSearching for GENDERS definition:" rg "GENDERS.*=" -A 5Length of output: 3148
Clarification on the Synchronized Use of Gender Constants
The investigation confirms that
GENDER_TYPES
insrc/common/constants.tsx
is the detailed source (providing id, text, and icon for each gender) and thatGENDERS
is directly derived asGENDER_TYPES.map((gender) => gender.id)
. This design ensures the two remain synchronized by default. However, please be mindful that any modifications toGENDER_TYPES
(such as adding, removing, or updating gender objects) will automatically affectGENDERS
used in validation.
File:
src/common/constants.tsx
- GENDER_TYPES: Array containing full gender details.
- GENDERS: Derived array of gender IDs for validation.
Usage Example in
src/components/Users/UserForm.tsx
:import { GENDER_TYPES } from "@/common/constants"; import { GENDERS } from "@/common/constants";To maintain clarity and reduce future confusion, consider adding inline documentation that explicitly states the dependency between these constants.
@AdityaJ2305 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌 |
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit