Skip to content

fix: Role not getting updated immediately in edit profile modal#23236

Merged
anikdhabal merged 3 commits intocalcom:mainfrom
asadath1395:fix/role-not-reflected-immd
Aug 27, 2025
Merged

fix: Role not getting updated immediately in edit profile modal#23236
anikdhabal merged 3 commits intocalcom:mainfrom
asadath1395:fix/role-not-reflected-immd

Conversation

@asadath1395
Copy link
Contributor

@asadath1395 asadath1395 commented Aug 21, 2025

What does this PR do?

Role not getting updated immediately in edit profile modal

  • Fixes #XXXX (GitHub issue number)
  • Fixes CAL-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

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)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Create a team
  • Invite a new user to the team
  • Edit the user's role

@vercel
Copy link

vercel bot commented Aug 21, 2025

@asadath1395 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 21, 2025

Walkthrough

This 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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Aug 21, 2025
@graphite-app graphite-app bot requested a review from a team August 21, 2025 06:10
@graphite-app
Copy link

graphite-app bot commented Aug 21, 2025

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.

@dosubot dosubot bot added teams area: teams, round robin, collective, managed event-types 🐛 bug Something isn't working labels Aug 21, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (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 User from ./MemberList couples this modal to a sibling UI file and risks accidental cycles. Consider lifting User (the RouterOutputs alias) into a shared types.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 User to lock the contract and prevent accidental widening.
  • Optionally tighten customRoles to the shape your UI consumes for customRole (at least { id: string; name: string }) and document that unknown custom-role IDs yield customRole: 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 getUpdatedUser from the modal introduces cross-component coupling. Consider moving getUpdatedUser (and updateRoleInCache) into a small role-utils.ts alongside 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.

📥 Commits

Reviewing files that changed from the base of the PR and between b9aee3b and 74ac698.

📒 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.tsx
  • packages/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.tsx
  • packages/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.tsx
  • packages/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 passing customRoles when available for a better optimistic UI.

Using getUpdatedUser here is solid. If the caller has customRoles, pass them through so the optimistic cache also shows the custom-role name immediately (not just the customRoleId). 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 customRoles hasn’t loaded yet, the computed customRole will be null and the UI may briefly show the old traditional role label. If that flicker shows up, gate the dispatch on customRoles readiness or re-dispatch once roles load.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 21, 2025

E2E results are ready!

@anikdhabal anikdhabal enabled auto-merge (squash) August 26, 2025 16:24
@anikdhabal anikdhabal merged commit 740a1c9 into calcom:main Aug 27, 2025
31 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working community Created by Linear-GitHub Sync ready-for-e2e teams area: teams, round robin, collective, managed event-types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants