fix: Role not getting updated immediately in edit profile modal#23236
fix: Role not getting updated immediately in edit profile modal#23236anikdhabal merged 3 commits intocalcom:mainfrom
Conversation
|
@asadath1395 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis change introduces and consumes a new helper for role updates. MemberChangeRoleModal.tsx adds an exported getUpdatedUser(member, role, customRoles) function to compute an updated User, and refactors internal cache update logic to use it. EditMemberSheet.tsx now imports getUpdatedUser and, after a successful role change (post cache invalidation and success toast), dispatches an EDIT_USER_SHEET action with payload { showModal: true, user: getUpdatedUser(selectedUser, role, customRoles) } to present an updated user sheet modal. Possibly related PRs
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (08/21/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add community label" took an action on this PR • (08/21/25)1 label was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (08/21/25)1 label was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/features/ee/teams/components/MemberChangeRoleModal.tsx (2)
12-13: Avoid importing types from a UI component; move shared types to a stable module.Importing
Userfrom./MemberListcouples this modal to a sibling UI file and risks accidental cycles. Consider liftingUser(the RouterOutputs alias) into a sharedtypes.ts(or a central API types module) and import from there.
19-36: Make the return type explicit and keep the helper narrowly typed.The logic looks correct for transitioning between traditional and custom roles. Two small improvements:
- Declare the return type as
Userto lock the contract and prevent accidental widening.- Optionally tighten
customRolesto the shape your UI consumes forcustomRole(at least{ id: string; name: string }) and document that unknown custom-role IDs yieldcustomRole: null.Apply this diff:
-export const getUpdatedUser = ( +export const getUpdatedUser = ( member: User, role: MembershipRole | string, customRoles: { id: string; name: string }[] | undefined -) => { +): User => { const isTraditionalRole = Object.values(MembershipRole).includes(role as MembershipRole); // Find the new custom role object if assigning a custom role const newCustomRole = !isTraditionalRole && customRoles ? customRoles.find((cr) => cr.id === role) || null : null; return { ...member, role: isTraditionalRole ? (role as MembershipRole) : member.role, customRoleId: isTraditionalRole ? null : (role as string), customRole: newCustomRole, }; };packages/features/ee/teams/components/EditMemberSheet.tsx (1)
23-23: Decouple cross-component utilities.Importing
getUpdatedUserfrom the modal introduces cross-component coupling. Consider movinggetUpdatedUser(andupdateRoleInCache) into a smallrole-utils.tsalongside shared types to avoid UI-to-UI imports and ease reuse/testing.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/features/ee/teams/components/EditMemberSheet.tsx(2 hunks)packages/features/ee/teams/components/MemberChangeRoleModal.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Always use
t()for text localization in frontend code; direct text embedding should trigger a warning
Files:
packages/features/ee/teams/components/MemberChangeRoleModal.tsxpackages/features/ee/teams/components/EditMemberSheet.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/features/ee/teams/components/MemberChangeRoleModal.tsxpackages/features/ee/teams/components/EditMemberSheet.tsx
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/ee/teams/components/MemberChangeRoleModal.tsxpackages/features/ee/teams/components/EditMemberSheet.tsx
🧬 Code graph analysis (2)
packages/features/ee/teams/components/MemberChangeRoleModal.tsx (2)
packages/platform/libraries/index.ts (1)
MembershipRole(98-98)packages/features/ee/teams/components/MemberList.tsx (1)
User(73-73)
packages/features/ee/teams/components/EditMemberSheet.tsx (1)
packages/features/ee/teams/components/MemberChangeRoleModal.tsx (1)
getUpdatedUser(19-36)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
packages/features/ee/teams/components/MemberChangeRoleModal.tsx (1)
71-74: Good reuse; consider passingcustomRoleswhen available for a better optimistic UI.Using
getUpdatedUserhere is solid. If the caller hascustomRoles, pass them through so the optimistic cache also shows the custom-role name immediately (not just thecustomRoleId). If not available here, that’s fine—server invalidation will correct it.packages/features/ee/teams/components/EditMemberSheet.tsx (1)
146-152: This fixes the immediate-reflect bug; add a small guard for custom roles.Dispatching an updated user right after success addresses the stale data in the sheet. As a minor improvement, if
customRoleshasn’t loaded yet, the computedcustomRolewill benulland the UI may briefly show the old traditional role label. If that flicker shows up, gate the dispatch oncustomRolesreadiness or re-dispatch once roles load.
E2E results are ready! |
What does this PR do?
Role not getting updated immediately in edit profile modal
Visual Demo (For contributors especially)
Video Demo (if applicable):
Before
Screen.Recording.2025-08-21.at.11.38.01.AM.mov
After
Screen.Recording.2025-08-21.at.11.36.00.AM.mov
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?