Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/features/ee/teams/components/EditMemberSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Skeleton, Loader } from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";

import { updateRoleInCache } from "./MemberChangeRoleModal";
import { updateRoleInCache, getUpdatedUser } from "./MemberChangeRoleModal";
import type { Action, State, User } from "./MemberList";

const formSchema = z.object({
Expand Down Expand Up @@ -142,6 +142,14 @@ export function EditMemberSheet({
await utils.viewer.teams.listMembers.invalidate();
showToast(t("profile_updated_successfully"), "success");
setEditMode(false);

dispatch({
type: "EDIT_USER_SHEET",
payload: {
showModal: true,
user: getUpdatedUser(selectedUser, role, customRoles),
},
});
},
async onError(err) {
showToast(err.message, "error");
Expand Down
34 changes: 22 additions & 12 deletions packages/features/ee/teams/components/MemberChangeRoleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@ import { Button } from "@calcom/ui/components/button";
import { DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
import { Select } from "@calcom/ui/components/form";

import type { User } from "./MemberList";

type MembershipRoleOption = {
label: string;
value: MembershipRole;
};

export const getUpdatedUser = (
member: User,
role: MembershipRole | string,
customRoles: { id: string; name: string }[] | undefined
) => {
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,
};
};

export const updateRoleInCache = ({
utils,
teamId,
Expand Down Expand Up @@ -49,18 +70,7 @@ export const updateRoleInCache = ({
...page,
members: page.members.map((member) => {
if (member.id === memberId) {
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,
};
return getUpdatedUser(member, role, customRoles);
}
return member;
}),
Expand Down
Loading