From 86d6f5bd344ab6a5e58c565ab98b49846e64129d Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 9 Jun 2023 11:26:12 +0200 Subject: [PATCH 1/5] using personalDetails in getDisplayNamesWithTooltips --- src/libs/ReportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 2fc9173f136d..13694c512e90 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -886,10 +886,10 @@ function getDisplayNameForParticipant(accountID, shouldUseShortForm = false) { */ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) { return _.map(participants, (participant) => { + const personalDetails = getPersonalDetailsForAccountID(participant.accountID); const displayName = getDisplayNameForParticipant(participant.accountID, isMultipleParticipantReport); - // TODO: Maybe get login from personal details via participant accountID? - const tooltip = participant.login ? Str.removeSMSDomain(participant.login) : ''; + const tooltip = personalDetails.login ? Str.removeSMSDomain(personalDetails.login) : ''; let pronouns = participant.pronouns; if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) { From 8099f81f873b2898418eae9951e697df63867e73 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 9 Jun 2023 11:32:49 +0200 Subject: [PATCH 2/5] using personalDetails in buildOptimisticIOUReport --- src/libs/ReportUtils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 13694c512e90..88b3b0b9223a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -838,14 +838,14 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false) /** * Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx, * then a default object is constructed. - * @param {String} accountID + * @param {Number} accountID * @returns {Object} */ function getPersonalDetailsForAccountID(accountID) { if (!accountID) { return {}; } - if (Number(accountID) === CONST.ACCOUNT_ID.CONCIERGE) { + if (accountID === CONST.ACCOUNT_ID.CONCIERGE) { return { accountID, displayName: 'Concierge', @@ -862,7 +862,7 @@ function getPersonalDetailsForAccountID(accountID) { /** * Get the displayName for a single report participant. * - * @param {String} accountID + * @param {Number} accountID * @param {Boolean} [shouldUseShortForm] * @returns {String} */ @@ -1215,8 +1215,8 @@ function buildOptimisticTaskCommentReportAction(taskReportID, taskTitle, taskAss */ function buildOptimisticIOUReport(payeeEmail, payeeAccountID, payerAccountID, total, chatReportID, currency, isSendingMoney = false) { const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); - // TODO: GET ME - const payerEmail = 'GET ME WITH PERSONAL DETAILS'; + const personalDetails = getPersonalDetailsForAccountID(payerAccountID); + const payerEmail = personalDetails.login; return { // If we're sending money, hasOutstandingIOU should be false hasOutstandingIOU: !isSendingMoney, From 90a5ba80d5ff37aa3f5d013ab3ee2707970aa211 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 9 Jun 2023 13:42:15 +0200 Subject: [PATCH 3/5] todo from removeUsers method of WorkspaceMembersPage addressed --- src/libs/actions/Policy.js | 21 ++++++----- src/pages/workspace/WorkspaceMembersPage.js | 39 ++++++++++----------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 654419ce57b9..6645e976ac1c 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -60,6 +60,12 @@ Onyx.connect({ }, }); +let personalDetails; +Onyx.connect({ + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + callback: (val) => (personalDetails = val), +}); + /** * Stores in Onyx the policy ID of the last workspace that was accessed by the user * @param {String|null} policyID @@ -187,14 +193,13 @@ function hasActiveFreePolicy(policies) { /** * Remove the passed members from the policy employeeList * - * @param {Array} members * @param {Array} accountIDs * @param {String} policyID */ -function removeMembers(members, accountIDs, policyID) { +function removeMembers(accountIDs, policyID) { // In case user selects only themselves (admin), their email will be filtered out and the members - // array passed will be empty, prevent the function from proceeding in that case as there is noone to remove - if (members.length === 0) { + // array passed will be empty, prevent the function from proceeding in that case as there is no one to remove + if (accountIDs.length === 0) { return; } const membersListKey = `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`; @@ -202,27 +207,27 @@ function removeMembers(members, accountIDs, policyID) { { onyxMethod: Onyx.METHOD.MERGE, key: membersListKey, - value: _.object(accountIDs, Array(members.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})), + value: _.object(accountIDs, Array(accountIDs.length).fill({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})), }, ]; const successData = [ { onyxMethod: Onyx.METHOD.MERGE, key: membersListKey, - value: _.object(accountIDs, Array(members.length).fill(null)), + value: _.object(accountIDs, Array(accountIDs.length).fill(null)), }, ]; const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, key: membersListKey, - value: _.object(accountIDs, Array(members.length).fill({errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')})), + value: _.object(accountIDs, Array(accountIDs.length).fill({errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')})), }, ]; API.write( 'DeleteMembersFromWorkspace', { - emailList: members.join(','), + emailList: _.map(accountIDs, (accountID) => personalDetails[accountID].login).join(','), policyID, }, {optimisticData, successData, failureData}, diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index 73e54848bc2e..417dc7124f09 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -182,12 +182,9 @@ class WorkspaceMembersPage extends React.Component { } // Remove the admin from the list - const membersToRemove = _.without(this.state.selectedEmployees, this.props.session.email); + const accountIDsToRemove = _.without(this.state.selectedEmployees, this.props.session.accountID); - // It's a pain, but we need to map the emails back to accountIDs now so we can set optimistic data. TODO removeMembers using accountIDs only. - const emailsToAccountIDs = PolicyUtils.getClientPolicyMemberEmailsToAccountIDs(this.props.policyMembers, this.props.personalDetails); - const accountIDsToRemove = _.map(membersToRemove, (email) => emailsToAccountIDs[email]); - Policy.removeMembers(membersToRemove, accountIDsToRemove, this.props.route.params.policyID); + Policy.removeMembers(accountIDsToRemove, this.props.route.params.policyID); this.setState({ selectedEmployees: [], isRemoveMembersConfirmModalVisible: false, @@ -229,32 +226,32 @@ class WorkspaceMembersPage extends React.Component { /** * Toggle user from the selectedEmployees list * - * @param {String} login + * @param {String} accountID * @param {String} pendingAction * */ - toggleUser(login, pendingAction) { + toggleUser(accountID, pendingAction) { if (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { return; } // Add or remove the user if the checkbox is enabled - if (_.contains(this.state.selectedEmployees, login)) { - this.removeUser(login); + if (_.contains(this.state.selectedEmployees, accountID)) { + this.removeUser(accountID); } else { - this.addUser(login); + this.addUser(accountID); } } /** * Add user from the selectedEmployees list * - * @param {String} login + * @param {String} accountID */ - addUser(login) { + addUser(accountID) { this.setState( (prevState) => ({ - selectedEmployees: [...prevState.selectedEmployees, login], + selectedEmployees: [...prevState.selectedEmployees, accountID], }), () => this.validate(), ); @@ -263,12 +260,12 @@ class WorkspaceMembersPage extends React.Component { /** * Remove user from the selectedEmployees list * - * @param {String} login + * @param {String} accountID */ - removeUser(login) { + removeUser(accountID) { this.setState( (prevState) => ({ - selectedEmployees: _.without(prevState.selectedEmployees, login), + selectedEmployees: _.without(prevState.selectedEmployees, accountID), }), () => this.validate(), ); @@ -322,7 +319,7 @@ class WorkspaceMembersPage extends React.Component { * @returns {React.Component} */ renderItem({item}) { - const isChecked = _.contains(this.state.selectedEmployees, item.login); + const isChecked = _.contains(this.state.selectedEmployees, item.accountID); return ( this.toggleUser(item.login, item.pendingAction)} + onPress={() => this.toggleUser(item.accountID, item.pendingAction)} accessibilityRole="checkbox" accessibilityState={{ checked: isChecked, @@ -344,7 +341,7 @@ class WorkspaceMembersPage extends React.Component { > this.toggleUser(item.login, item.pendingAction)} + onPress={() => this.toggleUser(item.accountID, item.pendingAction)} /> _.contains(this.state.selectedEmployees, memberEmail)) + !_.isEmpty(removableMembers) && _.every(_.keys(removableMembers), (accountID) => _.contains(this.state.selectedEmployees, accountID)) } onPress={() => this.toggleAllUsers(removableMembers)} /> From decad9ec2d4efdd85a9a807a73f310c6a67bef45 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 9 Jun 2023 13:54:21 +0200 Subject: [PATCH 4/5] prettier + lint applied --- src/libs/actions/Report.js | 1 - src/pages/home/report/ReportActionItemSingle.js | 2 +- src/pages/workspace/WorkspaceMembersPage.js | 4 +--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 52b2a291b1a2..6a98fc5818f3 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -18,7 +18,6 @@ import Log from '../Log'; import * as ReportUtils from '../ReportUtils'; import DateUtils from '../DateUtils'; import * as ReportActionsUtils from '../ReportActionsUtils'; -import * as OptionsListUtils from '../OptionsListUtils'; import * as CollectionUtils from '../CollectionUtils'; import * as EmojiUtils from '../EmojiUtils'; import * as ErrorUtils from '../ErrorUtils'; diff --git a/src/pages/home/report/ReportActionItemSingle.js b/src/pages/home/report/ReportActionItemSingle.js index 8e61602162ee..61eee7ee9801 100644 --- a/src/pages/home/report/ReportActionItemSingle.js +++ b/src/pages/home/report/ReportActionItemSingle.js @@ -66,7 +66,7 @@ const showUserDetails = (accountID) => { }; const ReportActionItemSingle = (props) => { - const actorEmail = lodashGet(props.action, actorEmail, '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); + const actorEmail = lodashGet(props.action, 'actorEmail', '').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); const actorAccountID = props.action.actorAccountID; const {avatar, displayName, pendingFields} = props.personalDetailsList[actorAccountID] || {}; const avatarSource = UserUtils.getAvatar(avatar, actorAccountID); diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index 417dc7124f09..b8bdfba30fd5 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -474,9 +474,7 @@ class WorkspaceMembersPage extends React.Component { _.contains(this.state.selectedEmployees, accountID)) - } + isChecked={!_.isEmpty(removableMembers) && _.every(_.keys(removableMembers), (accountID) => _.contains(this.state.selectedEmployees, accountID))} onPress={() => this.toggleAllUsers(removableMembers)} /> From f16bb613715aa7523fdd38b58781226256ace298 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 9 Jun 2023 15:41:51 +0200 Subject: [PATCH 5/5] casting to number reverted --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 88b3b0b9223a..181df5ec442c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -845,7 +845,7 @@ function getPersonalDetailsForAccountID(accountID) { if (!accountID) { return {}; } - if (accountID === CONST.ACCOUNT_ID.CONCIERGE) { + if (Number(accountID) === CONST.ACCOUNT_ID.CONCIERGE) { return { accountID, displayName: 'Concierge',