Skip to content

Commit

Permalink
Merge pull request #40428 from Expensify/monil-fixWorkspaceMemberOptions
Browse files Browse the repository at this point in the history
[CP Stag] Fix workspace role change options

(cherry picked from commit 168ce62)
  • Loading branch information
AndrewGable authored and OSBotify committed Apr 19, 2024
1 parent 3add4c7 commit 961003d
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft,
return;
}

const accountIDsToUpdate = selectedEmployees.filter((id) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[id]]?.role !== role);
const accountIDsToUpdate = selectedEmployees.filter((accountID) => {
const email = personalDetails?.[accountID]?.login ?? '';
return policy?.employeeList?.[email]?.role !== role;
});

Policy.updateWorkspaceMembersRole(route.params.policyID, accountIDsToUpdate, role);
setSelectedEmployees([]);
Expand All @@ -470,24 +473,30 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft,
},
];

if (PolicyUtils.isPaidGroupPolicy(policy)) {
if (selectedEmployees.find((employeeEmail) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[employeeEmail]]?.role === CONST.POLICY.ROLE.ADMIN)) {
options.push({
text: translate('workspace.people.makeMember'),
value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_MEMBER,
icon: Expensicons.User,
onSelected: () => changeUserRole(CONST.POLICY.ROLE.USER),
});
}
if (!PolicyUtils.isPaidGroupPolicy(policy)) {
return options;
}

if (selectedEmployees.find((employeeEmail) => policy?.employeeList?.[policyMemberEmailsToAccountIDs[employeeEmail]]?.role === CONST.POLICY.ROLE.USER)) {
options.push({
text: translate('workspace.people.makeAdmin'),
value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_ADMIN,
icon: Expensicons.MakeAdmin,
onSelected: () => changeUserRole(CONST.POLICY.ROLE.ADMIN),
});
}
const selectedEmployeesRoles = selectedEmployees.map((accountID) => {
const email = personalDetails?.[accountID]?.login ?? '';
return policy?.employeeList?.[email]?.role;
});
if (selectedEmployeesRoles.find((role) => role === CONST.POLICY.ROLE.ADMIN)) {
options.push({
text: translate('workspace.people.makeMember'),
value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_MEMBER,
icon: Expensicons.User,
onSelected: () => changeUserRole(CONST.POLICY.ROLE.USER),
});
}

if (selectedEmployeesRoles.find((role) => role === CONST.POLICY.ROLE.USER)) {
options.push({
text: translate('workspace.people.makeAdmin'),
value: CONST.POLICY.MEMBERS_BULK_ACTION_TYPES.MAKE_ADMIN,
icon: Expensicons.MakeAdmin,
onSelected: () => changeUserRole(CONST.POLICY.ROLE.ADMIN),
});
}
return options;
};
Expand Down

0 comments on commit 961003d

Please sign in to comment.