Skip to content

Commit

Permalink
Merge pull request #29422 from esh-g/workspace-admin-checkbox
Browse files Browse the repository at this point in the history
Workspace admin checkbox
  • Loading branch information
marcaaron authored Oct 16, 2023
2 parents 22874c7 + 6891b3c commit 7eca60b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function getMemberAccountIDsForWorkspace(policyMembers, personalDetails) {
if (!personalDetail || !personalDetail.login) {
return;
}
memberEmailsToAccountIDs[personalDetail.login] = accountID;
memberEmailsToAccountIDs[personalDetail.login] = Number(accountID);
});
return memberEmailsToAccountIDs;
}
Expand Down
30 changes: 13 additions & 17 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function WorkspaceMembersPage(props) {
const [errors, setErrors] = useState({});
const [searchValue, setSearchValue] = useState('');
const prevIsOffline = usePrevious(props.network.isOffline);
const accountIDs = useMemo(() => _.keys(props.policyMembers), [props.policyMembers]);
const accountIDs = useMemo(() => _.map(_.keys(props.policyMembers), (accountID) => Number(accountID)), [props.policyMembers]);
const prevAccountIDs = usePrevious(accountIDs);
const textInputRef = useRef(null);
const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline;
Expand Down Expand Up @@ -116,12 +116,7 @@ function WorkspaceMembersPage(props) {
if (removeMembersConfirmModalVisible && !_.isEqual(accountIDs, prevAccountIDs)) {
setRemoveMembersConfirmModalVisible(false);
}
setSelectedEmployees((prevSelected) =>
_.intersection(
prevSelected,
_.map(_.values(PolicyUtils.getMemberAccountIDsForWorkspace(props.policyMembers, props.personalDetails)), (accountID) => Number(accountID)),
),
);
setSelectedEmployees((prevSelected) => _.intersection(prevSelected, _.values(PolicyUtils.getMemberAccountIDsForWorkspace(props.policyMembers, props.personalDetails))));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.policyMembers]);

Expand Down Expand Up @@ -173,12 +168,12 @@ function WorkspaceMembersPage(props) {
*/
const toggleAllUsers = (memberList) => {
const enabledAccounts = _.filter(memberList, (member) => !member.isDisabled);
const everyoneSelected = _.every(enabledAccounts, (member) => _.contains(selectedEmployees, Number(member.keyForList)));
const everyoneSelected = _.every(enabledAccounts, (member) => _.contains(selectedEmployees, member.accountID));

if (everyoneSelected) {
setSelectedEmployees([]);
} else {
const everyAccountId = _.map(enabledAccounts, (member) => Number(member.keyForList));
const everyAccountId = _.map(enabledAccounts, (member) => member.accountID);
setSelectedEmployees(everyAccountId);
}

Expand Down Expand Up @@ -225,10 +220,10 @@ function WorkspaceMembersPage(props) {
}

// Add or remove the user if the checkbox is enabled
if (_.contains(selectedEmployees, Number(accountID))) {
removeUser(Number(accountID));
if (_.contains(selectedEmployees, accountID)) {
removeUser(accountID);
} else {
addUser(Number(accountID));
addUser(accountID);
}
},
[selectedEmployees, addUser, removeUser],
Expand Down Expand Up @@ -265,7 +260,8 @@ function WorkspaceMembersPage(props) {
const getMemberOptions = () => {
let result = [];

_.each(props.policyMembers, (policyMember, accountID) => {
_.each(props.policyMembers, (policyMember, accountIDKey) => {
const accountID = Number(accountIDKey);
if (isDeletedPolicyMember(policyMember)) {
return;
}
Expand Down Expand Up @@ -313,9 +309,9 @@ function WorkspaceMembersPage(props) {
const isAdmin = props.session.email === details.login || policyMember.role === CONST.POLICY.ROLE.ADMIN;

result.push({
keyForList: accountID,
accountID: Number(accountID),
isSelected: _.contains(selectedEmployees, Number(accountID)),
keyForList: accountIDKey,
accountID,
isSelected: _.contains(selectedEmployees, accountID),
isDisabled:
accountID === props.session.accountID ||
details.login === props.policy.owner ||
Expand Down Expand Up @@ -417,7 +413,7 @@ function WorkspaceMembersPage(props) {
textInputValue={searchValue}
onChangeText={setSearchValue}
headerMessage={getHeaderMessage()}
onSelectRow={(item) => toggleUser(item.keyForList)}
onSelectRow={(item) => toggleUser(item.accountID)}
onSelectAll={() => toggleAllUsers(data)}
onDismissError={dismissError}
showLoadingPlaceholder={!isOfflineAndNoMemberDataAvailable && (!OptionsListUtils.isPersonalDetailsReady(props.personalDetails) || _.isEmpty(props.policyMembers))}
Expand Down

0 comments on commit 7eca60b

Please sign in to comment.