[WEB-2857]fix: updating user role in profile#6278
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Sequence DiagramsequenceDiagram
participant User
participant ProfilePage
participant UserHook
participant ProfileHook
participant API
User->>ProfilePage: Update Profile
ProfilePage->>UserHook: Get Current User
ProfilePage->>ProfileHook: Get User Profile
ProfilePage->>ProfilePage: Prepare Payloads
ProfilePage->>API: Update User (Parallel)
ProfilePage->>API: Update Profile
API-->>ProfilePage: Update Confirmation
ProfilePage->>User: Show Success Message
Possibly related PRs
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 (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
web/app/profile/page.tsx (3)
30-30: Validate the combined usage ofuseUseranduseUserProfile.While splitting user data and user profile data can improve semantic clarity, confirm that this separation won't introduce race conditions or partial updates. If these updates are meant to be atomic, consider consolidating them.
62-62: Check naming consistency and clarity.The variable
currentUserProfileclosely parallelscurrentUser. Consider consistently naming them (e.g.,userProfilevs.currentUserProfile) for clarity across the codebase.
77-79: Use optional chaining carefully.
formData.role ?? undefinedworks, but confirm that returningundefinedis the intended behavior whenroleis absent, rather than preserving a default role or skipping the field entirely.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
web/app/profile/page.tsx(3 hunks)
🔇 Additional comments (5)
web/app/profile/page.tsx (5)
8-8: Use the newly imported TUserProfile judiciously.
Importing TUserProfile is good for typing your user profile data. Ensure that it's used consistently across the file and that the shape of the user profile in the store/context aligns with this new type.
65-65: Ensure correct priority during form reset.
Combining defaultValues, currentUser, and currentUserProfile is helpful for a comprehensive reset. Verify that merging these objects does not accidentally overwrite fields from the other sources.
70-70: Confirm completeness of the user payload.
You might also consider including role in the userPayload if a user’s role in the user entity must always mirror the profile’s role. If this is intentional, disregard.
82-83: Cover image logic might cause confusion.
If formData.cover_image_url starts with http, the logic sets cover_image but clears cover_image_asset. Confirm that all references to cover images consistently read from cover_image or cover_image_asset. Mismatches can lead to unexpected display behavior.
86-89: Parallel updates look good.
The Promise.all usage to update both the user and user profile is efficient. The success and error handling flow is clearly defined. Great job!
Description
This update ensures that the user's role is properly updated when the profile is submitted.
The
updateUserProfilefunction is now included in thePromise.allcall within theonSubmitfunction to handle role updates.Type of Change
References
WEB-2857
Summary by CodeRabbit
New Features
Bug Fixes
Improvements