From 21aea003c513415854dd1e671267c15804b7cd29 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Sun, 2 Jul 2023 18:41:52 -0400 Subject: [PATCH 1/5] Start migrating report.managerEmail --- src/components/ReportActionItem/IOUPreview.js | 3 --- src/components/ReportActionItem/ReportPreview.js | 8 ++++---- src/components/ReportActionItem/TaskAction.js | 4 ++-- src/components/ReportActionItem/TaskPreview.js | 15 ++++++++++++--- src/libs/IOUUtils.js | 6 ++---- src/libs/ReportUtils.js | 5 ++--- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/ReportActionItem/IOUPreview.js b/src/components/ReportActionItem/IOUPreview.js index f3878c2f2acb..ae802bb5ce67 100644 --- a/src/components/ReportActionItem/IOUPreview.js +++ b/src/components/ReportActionItem/IOUPreview.js @@ -57,9 +57,6 @@ const propTypes = { /** Active IOU Report for current report */ iouReport: PropTypes.shape({ - /** Email address of the manager in this iou report */ - managerEmail: PropTypes.string, - /** Account ID of the manager in this iou report */ managerID: PropTypes.number, diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 8321fcde825a..52ca9bcd18f1 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -47,8 +47,8 @@ const propTypes = { /** Active IOU Report for current report */ iouReport: PropTypes.shape({ - /** Email address of the manager in this iou report */ - managerEmail: PropTypes.string, + /** AccountID of the manager in this iou report */ + managerID: PropTypes.number, /** Email address of the creator of this iou report */ ownerEmail: PropTypes.string, @@ -93,8 +93,8 @@ const defaultProps = { }; function ReportPreview(props) { - const managerEmail = props.iouReport.managerEmail || ''; - const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); + const managerID = props.iouReport.managerID || 0; + const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const displayingMessage = ReportUtils.getReportPreviewMessage(props.iouReport, props.action); return ( diff --git a/src/components/ReportActionItem/TaskAction.js b/src/components/ReportActionItem/TaskAction.js index bdf8f374dde3..0c97f53d57ca 100644 --- a/src/components/ReportActionItem/TaskAction.js +++ b/src/components/ReportActionItem/TaskAction.js @@ -22,8 +22,8 @@ const propTypes = { /** Title of the task */ reportName: PropTypes.string, - /** Email address of the manager in this iou report */ - managerEmail: PropTypes.string, + /** AccountID of the manager in this iou report */ + managerID: PropTypes.number, /** Email address of the creator of this iou report */ ownerEmail: PropTypes.string, diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 4f29f6d39984..cadef4077030 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -2,6 +2,7 @@ import React from 'react'; import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; +import lodashGet from 'lodash/get'; import compose from '../../libs/compose'; import styles from '../../styles/styles'; import ONYXKEYS from '../../ONYXKEYS'; @@ -18,6 +19,7 @@ import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes import * as TaskUtils from '../../libs/actions/Task'; import RenderHTML from '../RenderHTML'; import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback'; +import personalDetailsPropType from '../../pages/personalDetailsPropType'; const propTypes = { /** The ID of the associated taskReport */ @@ -35,19 +37,23 @@ const propTypes = { /** Title of the task */ reportName: PropTypes.string, - /** Email address of the manager in this iou report */ - managerEmail: PropTypes.string, + /** AccountID of the manager in this iou report */ + managerID: PropTypes.number, /** Email address of the creator of this iou report */ ownerEmail: PropTypes.string, }), + /** Personal details of all users */ + personalDetails: PropTypes.objectOf(personalDetailsPropType), + ...withLocalizePropTypes, }; const defaultProps = { taskReport: {}, isHovered: false, + personalDetails: {}, }; function TaskPreview(props) { @@ -58,7 +64,7 @@ function TaskPreview(props) { ? props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED : props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED; const taskTitle = props.taskReport.reportName || props.action.childReportName; - const taskAssignee = props.taskReport.managerEmail || props.action.childManagerEmail; + const taskAssignee = lodashGet(props.personalDetails, [props.taskReport.managerID, 'login']) || props.action.childManagerEmail; const htmlForTaskPreview = taskAssignee ? `@${taskAssignee} ${taskTitle}` : `${taskTitle}`; return ( @@ -103,5 +109,8 @@ export default compose( taskReport: { key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, }, + personalDetails: { + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + }, }), )(TaskPreview); diff --git a/src/libs/IOUUtils.js b/src/libs/IOUUtils.js index 371243345eb6..a21351be29bb 100644 --- a/src/libs/IOUUtils.js +++ b/src/libs/IOUUtils.js @@ -25,8 +25,8 @@ function calculateAmount(numberOfParticipants, total, isDefaultUser = false) { /** * The owner of the IOU report is the account who is owed money and the manager is the one who owes money! * In case the owner/manager swap, we need to update the owner of the IOU report and the report total, since it is always positive. - * For example: if user1 owes user2 $10, then we have: {ownerEmail: user2, managerEmail: user1, total: $10 (a positive amount, owed to user2)} - * If user1 requests $17 from user2, then we have: {ownerEmail: user1, managerEmail: user2, total: $7 (still a positive amount, but now owed to user1)} + * For example: if user1 owes user2 $10, then we have: {ownerEmail: user2, managerID: user1, total: $10 (a positive amount, owed to user2)} + * If user1 requests $17 from user2, then we have: {ownerEmail: user1, managerID: user2, total: $7 (still a positive amount, but now owed to user1)} * * @param {Object} iouReport * @param {Number} actorAccountID @@ -53,8 +53,6 @@ function updateIOUOwnerAndTotal(iouReport, actorAccountID, amount, currency, typ // The total sign has changed and hence we need to flip the manager and owner of the report. iouReportUpdate.ownerAccountID = iouReport.managerID; iouReportUpdate.managerID = iouReport.ownerAccountID; - iouReportUpdate.ownerEmail = iouReport.managerEmail; - iouReportUpdate.managerEmail = iouReport.ownerEmail; iouReportUpdate.total = -iouReportUpdate.total; } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 4ddbf032867c..415beff6c0e3 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -162,7 +162,7 @@ function isTaskCompleted(report) { * @returns {Boolean} */ function isTaskAssignee(report) { - return lodashGet(report, 'managerEmail') === currentUserEmail; + return lodashGet(report, 'managerID') === currentUserAccountID; } /** @@ -806,7 +806,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false, return [adminIcon, workspaceIcon]; } if (isIOUReport(report)) { - const email = isPayer ? report.managerEmail : report.ownerEmail; + const email = isPayer ? lodashGet(personalDetails, [report.managerID, 'login']) : report.ownerEmail; const accountID = isPayer ? report.managerID : report.ownerAccountID; return [ { @@ -1799,7 +1799,6 @@ function buildOptimisticTaskReport(ownerEmail, ownerAccountID, assigneeAccountID description, ownerEmail, ownerAccountID, - // managerEmail: assignee, managerID: assigneeAccountID, type: CONST.REPORT.TYPE.TASK, parentReportID, From efc4b9dbddf94aac89019ffcafc0d1d89ba9c15c Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 7 Jul 2023 17:34:39 +0300 Subject: [PATCH 2/5] Fix sneaky merge --- src/components/ReportActionItem/TaskPreview.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 2c5126d8d640..71315369a74f 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -3,10 +3,7 @@ import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; -<<<<<<< HEAD -======= import _ from 'underscore'; ->>>>>>> ed21fdaaf90f458f7a063eaeb346bff61bac133e import compose from '../../libs/compose'; import styles from '../../styles/styles'; import ONYXKEYS from '../../ONYXKEYS'; @@ -120,11 +117,7 @@ export default compose( taskReport: { key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, }, -<<<<<<< HEAD - personalDetails: { -======= personalDetailsList: { ->>>>>>> ed21fdaaf90f458f7a063eaeb346bff61bac133e key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, }), From cf514e7f681c0ab710d3dd8ea65628e63f5b5aea Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 7 Jul 2023 17:40:50 +0300 Subject: [PATCH 3/5] Clean up unused prop, idk how this got in here --- src/components/ReportActionItem/TaskPreview.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 71315369a74f..d0c1a3635417 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -48,9 +48,6 @@ const propTypes = { ownerEmail: PropTypes.string, }), - /** Personal details of all users */ - personalDetails: PropTypes.objectOf(personalDetailsPropType), - ...withLocalizePropTypes, }; @@ -58,7 +55,6 @@ const defaultProps = { personalDetailsList: {}, taskReport: {}, isHovered: false, - personalDetails: {}, }; function TaskPreview(props) { From bdd01a06c041af49ab4af4645e715be4057bbd50 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 7 Jul 2023 17:47:51 +0300 Subject: [PATCH 4/5] Clean up some logic --- src/components/ReportActionItem/ReportPreview.js | 8 ++++---- src/libs/ReportUtils.js | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index e54073265d24..13ae1f6520bd 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -63,8 +63,8 @@ const propTypes = { /** Session info for the currently logged in user. */ session: PropTypes.shape({ - /** Currently logged in user email */ - email: PropTypes.string, + /** Currently logged in user accountID */ + accountID: PropTypes.number, }), /** Popover context menu anchor, used for showing context menu */ @@ -86,13 +86,13 @@ const defaultProps = { iouReport: {}, checkIfContextMenuActive: () => {}, session: { - email: null, + accountID: null, }, }; function ReportPreview(props) { const managerID = props.iouReport.managerID || 0; - const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID', null); + const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID'); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const displayingMessage = ReportUtils.getReportPreviewMessage(props.iouReport, props.action); return ( diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 21c77fdccc92..48162d2928c9 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -801,13 +801,12 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false, return [adminIcon, workspaceIcon]; } if (isIOUReport(report)) { - const email = isPayer ? lodashGet(personalDetails, [report.managerID, 'login']) : report.ownerEmail; const accountID = isPayer ? report.managerID : report.ownerAccountID; return [ { id: accountID, source: UserUtils.getAvatar(lodashGet(personalDetails, [accountID, 'avatar']), accountID), - name: email, + name: lodashGet(personalDetails, [accountID, 'login']), type: CONST.ICON_TYPE_AVATAR, }, ]; From 7f51a8d688bedebfe15b590d55bec9d119f6cd65 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 15:24:08 -0400 Subject: [PATCH 5/5] prettier --- src/components/ReportActionItem/ReportPreview.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index b23feccab94a..c6aea508e409 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -89,8 +89,7 @@ function ReportPreview(props) { const managerID = props.iouReport.managerID || 0; const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID'); const reportAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.iouReport), props.iouReport.currency); - const managerName = - (ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true)); + const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); return (