diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 347a825f59cc..6bbae72f1d80 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -174,7 +174,7 @@ function getMemberAccountIDsForWorkspace(policyMembers, personalDetails) { if (!personalDetail || !personalDetail.login) { return; } - memberEmailsToAccountIDs[personalDetail.login] = accountID; + memberEmailsToAccountIDs[personalDetail.login] = Number(accountID); }); return memberEmailsToAccountIDs; } diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index b0aaa001817f..fb394721ff3c 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -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; @@ -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]); @@ -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); } @@ -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], @@ -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; } @@ -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 || @@ -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))}