Skip to content

Commit 740a1c9

Browse files
fix: Role not getting updated immediately in edit profile modal (calcom#23236)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
1 parent 70cfe8d commit 740a1c9

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

packages/features/ee/teams/components/EditMemberSheet.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Skeleton, Loader } from "@calcom/ui/components/skeleton";
2020
import { showToast } from "@calcom/ui/components/toast";
2121
import { Tooltip } from "@calcom/ui/components/tooltip";
2222

23-
import { updateRoleInCache } from "./MemberChangeRoleModal";
23+
import { updateRoleInCache, getUpdatedUser } from "./MemberChangeRoleModal";
2424
import type { Action, State, User } from "./MemberList";
2525

2626
const formSchema = z.object({
@@ -142,6 +142,14 @@ export function EditMemberSheet({
142142
await utils.viewer.teams.listMembers.invalidate();
143143
showToast(t("profile_updated_successfully"), "success");
144144
setEditMode(false);
145+
146+
dispatch({
147+
type: "EDIT_USER_SHEET",
148+
payload: {
149+
showModal: true,
150+
user: getUpdatedUser(selectedUser, role, customRoles),
151+
},
152+
});
145153
},
146154
async onError(err) {
147155
showToast(err.message, "error");

packages/features/ee/teams/components/MemberChangeRoleModal.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,32 @@ import { Button } from "@calcom/ui/components/button";
99
import { DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
1010
import { Select } from "@calcom/ui/components/form";
1111

12+
import type { User } from "./MemberList";
13+
1214
type MembershipRoleOption = {
1315
label: string;
1416
value: MembershipRole;
1517
};
1618

19+
export const getUpdatedUser = (
20+
member: User,
21+
role: MembershipRole | string,
22+
customRoles: { id: string; name: string }[] | undefined
23+
) => {
24+
const isTraditionalRole = Object.values(MembershipRole).includes(role as MembershipRole);
25+
26+
// Find the new custom role object if assigning a custom role
27+
const newCustomRole =
28+
!isTraditionalRole && customRoles ? customRoles.find((cr) => cr.id === role) || null : null;
29+
30+
return {
31+
...member,
32+
role: isTraditionalRole ? (role as MembershipRole) : member.role,
33+
customRoleId: isTraditionalRole ? null : (role as string),
34+
customRole: newCustomRole,
35+
};
36+
};
37+
1738
export const updateRoleInCache = ({
1839
utils,
1940
teamId,
@@ -49,18 +70,7 @@ export const updateRoleInCache = ({
4970
...page,
5071
members: page.members.map((member) => {
5172
if (member.id === memberId) {
52-
const isTraditionalRole = Object.values(MembershipRole).includes(role as MembershipRole);
53-
54-
// Find the new custom role object if assigning a custom role
55-
const newCustomRole =
56-
!isTraditionalRole && customRoles ? customRoles.find((cr) => cr.id === role) || null : null;
57-
58-
return {
59-
...member,
60-
role: isTraditionalRole ? (role as MembershipRole) : member.role,
61-
customRoleId: isTraditionalRole ? null : (role as string),
62-
customRole: newCustomRole,
63-
};
73+
return getUpdatedUser(member, role, customRoles);
6474
}
6575
return member;
6676
}),

0 commit comments

Comments
 (0)