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
  • Loading branch information
AndrewGable authored Apr 18, 2024
2 parents 8278ca9 + 8377e34 commit 168ce62
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 @@ -451,7 +451,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 @@ -467,24 +470,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 168ce62

Please sign in to comment.