From 46bcdad52619756a505782d9a030bafcc230546c Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Sun, 2 Jul 2023 17:40:08 -0400 Subject: [PATCH 1/4] Replace ownerEmail in a bunch of places --- src/components/ArchivedReportFooter.js | 2 +- src/components/OptionRow.js | 2 +- src/components/ReportActionItem/IOUPreview.js | 3 -- .../ReportActionItem/ReportPreview.js | 4 +- src/components/ReportActionItem/TaskAction.js | 4 +- .../ReportActionItem/TaskPreview.js | 4 +- src/components/ReportWelcomeText.js | 4 +- src/libs/E2E/apiMocks/openApp.js | 54 +++++++++---------- src/libs/E2E/apiMocks/openReport.js | 2 +- src/libs/IOUUtils.js | 6 +-- src/libs/OptionsListUtils.js | 8 +-- src/libs/ReportUtils.js | 9 ++-- src/libs/SidebarUtils.js | 2 - src/libs/actions/App.js | 4 +- src/libs/actions/Welcome.js | 6 +-- src/pages/iouReportPropTypes.js | 2 +- src/pages/reportPropTypes.js | 3 -- tests/unit/OptionsListUtilsTest.js | 1 - tests/unit/ReportUtilsTest.js | 3 -- 19 files changed, 54 insertions(+), 69 deletions(-) diff --git a/src/components/ArchivedReportFooter.js b/src/components/ArchivedReportFooter.js index d7a138d9a473..70741f352089 100644 --- a/src/components/ArchivedReportFooter.js +++ b/src/components/ArchivedReportFooter.js @@ -50,7 +50,7 @@ const defaultProps = { function ArchivedReportFooter(props) { const archiveReason = lodashGet(props.reportClosedAction, 'originalMessage.reason', CONST.REPORT.ARCHIVE_REASON.DEFAULT); - let displayName = PersonalDetailsUtils.getDisplayNameOrDefault(props.personalDetails, [props.report.ownerAccountID, 'displayName'], props.report.ownerEmail); + let displayName = PersonalDetailsUtils.getDisplayNameOrDefault(props.personalDetails, [props.report.ownerAccountID, 'displayName']); let oldDisplayName; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED) { diff --git a/src/components/OptionRow.js b/src/components/OptionRow.js index 14b16949de70..e7fcbc76a10c 100644 --- a/src/components/OptionRow.js +++ b/src/components/OptionRow.js @@ -100,7 +100,7 @@ class OptionRow extends Component { this.props.option.descriptiveText !== nextProps.option.descriptiveText || this.props.option.brickRoadIndicator !== nextProps.option.brickRoadIndicator || this.props.option.shouldShowSubscript !== nextProps.option.shouldShowSubscript || - this.props.option.ownerEmail !== nextProps.option.ownerEmail || + this.props.option.ownerAccountID !== nextProps.option.ownerAccountID || this.props.option.subtitle !== nextProps.option.subtitle || this.props.option.pendingAction !== nextProps.option.pendingAction || this.props.option.customIcon !== nextProps.option.customIcon diff --git a/src/components/ReportActionItem/IOUPreview.js b/src/components/ReportActionItem/IOUPreview.js index f3878c2f2acb..dbd777761b27 100644 --- a/src/components/ReportActionItem/IOUPreview.js +++ b/src/components/ReportActionItem/IOUPreview.js @@ -63,9 +63,6 @@ const propTypes = { /** Account ID of the manager in this iou report */ managerID: PropTypes.number, - /** Email address of the creator of this iou report */ - ownerEmail: PropTypes.string, - /** Account ID of the creator of this iou report */ ownerAccountID: PropTypes.number, diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 8321fcde825a..1fb174189d3d 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -50,8 +50,8 @@ const propTypes = { /** Email address of the manager in this iou report */ managerEmail: PropTypes.string, - /** Email address of the creator of this iou report */ - ownerEmail: PropTypes.string, + /** AccountID of the creator of this iou report */ + ownerAccountID: PropTypes.number, /** Outstanding amount in cents of this transaction */ total: PropTypes.number, diff --git a/src/components/ReportActionItem/TaskAction.js b/src/components/ReportActionItem/TaskAction.js index bdf8f374dde3..12a7b754a524 100644 --- a/src/components/ReportActionItem/TaskAction.js +++ b/src/components/ReportActionItem/TaskAction.js @@ -25,8 +25,8 @@ const propTypes = { /** Email address of the manager in this iou report */ managerEmail: PropTypes.string, - /** Email address of the creator of this iou report */ - ownerEmail: PropTypes.string, + /** AccountID of the creator of this iou report */ + ownerAccountID: PropTypes.number, }), ...withLocalizePropTypes, diff --git a/src/components/ReportActionItem/TaskPreview.js b/src/components/ReportActionItem/TaskPreview.js index 4f29f6d39984..88f64e847915 100644 --- a/src/components/ReportActionItem/TaskPreview.js +++ b/src/components/ReportActionItem/TaskPreview.js @@ -38,8 +38,8 @@ const propTypes = { /** Email address of the manager in this iou report */ managerEmail: PropTypes.string, - /** Email address of the creator of this iou report */ - ownerEmail: PropTypes.string, + /** AccountID of the creator of this iou report */ + ownerAccountID: PropTypes.number, }), ...withLocalizePropTypes, diff --git a/src/components/ReportWelcomeText.js b/src/components/ReportWelcomeText.js index 7c1b0252bee4..a08f01c91623 100644 --- a/src/components/ReportWelcomeText.js +++ b/src/components/ReportWelcomeText.js @@ -72,8 +72,8 @@ function ReportWelcomeText(props) { <> {props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne')} - {/* Use the policyExpenseChat owner's first name or their email if it's undefined or an empty string */} - {lodashGet(props.personalDetails, [props.report.ownerAccountID, 'firstName']) || props.report.ownerEmail} + {/* Use the policyExpenseChat owner's first name or their display name if it's undefined or an empty string */} + {lodashGet(props.personalDetails, [props.report.ownerAccountID, 'firstName']) || lodashGet(props.personalDetails, [props.report.ownerAccountID, 'displayName'], '')} {props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')} {ReportUtils.getPolicyName(props.report)} diff --git a/src/libs/E2E/apiMocks/openApp.js b/src/libs/E2E/apiMocks/openApp.js index 005bd005c5d4..8f8e6567e6d1 100644 --- a/src/libs/E2E/apiMocks/openApp.js +++ b/src/libs/E2E/apiMocks/openApp.js @@ -1573,7 +1573,7 @@ export default () => ({ reportID: '98258097', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['concierge@expensify.com'], isPinned: true, @@ -1599,7 +1599,7 @@ export default () => ({ reportID: '98258458', reportName: '', chatType: 'policyExpenseChat', - ownerEmail: 'applausetester+perf2@applause.expensifail.com', + ownerAccountID: 17, policyID: 'C28C2634DD7226B8', participants: ['applausetester@applause.expensifail.com', 'applausetester+perf2@applause.expensifail.com'], isPinned: false, @@ -1621,7 +1621,7 @@ export default () => ({ reportID: '98344717', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['applausetester+ihchat4@applause.expensifail.com'], isPinned: false, @@ -1643,7 +1643,7 @@ export default () => ({ reportID: '98345050', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake3@gmail.com'], isPinned: false, @@ -1665,7 +1665,7 @@ export default () => ({ reportID: '98345315', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake3@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'], isPinned: false, @@ -1687,7 +1687,7 @@ export default () => ({ reportID: '98345625', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake1@gmail.com', 'fake2@gmail.com', 'fake3@gmail.com', 'fake4@gmail.com', 'fake5@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'], isPinned: false, @@ -1709,7 +1709,7 @@ export default () => ({ reportID: '98345679', reportName: '', chatType: 'policyExpenseChat', - ownerEmail: 'applausetester+perf2@applause.expensifail.com', + ownerAccountID: 17, policyID: '1CE001C4B9F3CA54', participants: ['fake3@gmail.com', 'applausetester+perf2@applause.expensifail.com'], isPinned: false, @@ -1731,7 +1731,7 @@ export default () => ({ reportID: '98414813', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['applausetester+ihchat4@applause.expensifail.com', 'fake6@gmail.com'], isPinned: false, @@ -1753,7 +1753,7 @@ export default () => ({ reportID: '98817646', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake6@gmail.com'], isPinned: false, @@ -1776,7 +1776,7 @@ export default () => ({ reportID: '358751490033727', reportName: '#digimobileroom', chatType: 'policyRoom', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'C28C2634DD7226B8', participants: ['applausetester+pd1005@applause.expensifail.com'], isPinned: false, @@ -1798,7 +1798,7 @@ export default () => ({ reportID: '663424408122117', reportName: '#announce', chatType: 'policyAnnounce', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'A6511FF8D2EE7661', participants: ['applausetester+perf2@applause.expensifail.com'], isPinned: false, @@ -1820,7 +1820,7 @@ export default () => ({ reportID: '944123936554214', reportName: '', chatType: 'policyExpenseChat', - ownerEmail: 'applausetester+perf2@applause.expensifail.com', + ownerAccountID: 17, policyID: 'A6511FF8D2EE7661', participants: ['applausetester+perf2@applause.expensifail.com'], isPinned: false, @@ -1842,7 +1842,7 @@ export default () => ({ reportID: '2242399088152511', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: [ 'concierge@expensify.com', @@ -1870,7 +1870,7 @@ export default () => ({ reportID: '2576922422943214', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['applausetester+42222abb@applause.expensifail.com'], isPinned: false, @@ -1892,7 +1892,7 @@ export default () => ({ reportID: '2752461403207161', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake1@gmail.com'], isPinned: false, @@ -1914,7 +1914,7 @@ export default () => ({ reportID: '3785654888638968', reportName: '#jack', chatType: 'policyRoom', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'C28C2634DD7226B8', participants: ['applausetester+pd1005@applause.expensifail.com'], isPinned: false, @@ -1936,7 +1936,7 @@ export default () => ({ reportID: '4867098979334014', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['christoph+hightraffic@margelo.io'], isPinned: false, @@ -1959,7 +1959,7 @@ export default () => ({ reportID: '5277760851229035', reportName: '#kasper_tha_cat', chatType: 'policyRoom', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'C28C2634DD7226B8', participants: ['applausetester+pd1005@applause.expensifail.com'], isPinned: false, @@ -1983,7 +1983,7 @@ export default () => ({ reportID: '5324367938904284', reportName: '#applause.expensifail.com', chatType: 'domainAll', - ownerEmail: '+@applause.expensifail.com', + ownerAccountID: 99, policyID: '_FAKE_', participants: ['applausetester+bernardo@applause.expensifail.com'], isPinned: false, @@ -2005,7 +2005,7 @@ export default () => ({ reportID: '5654270288238256', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: [ 'andreylazutkinutest@gmail.com', @@ -2036,7 +2036,7 @@ export default () => ({ reportID: '6194900075541844', reportName: '#admins', chatType: 'policyAdmins', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'A6511FF8D2EE7661', participants: ['applausetester+perf2@applause.expensifail.com'], isPinned: false, @@ -2058,7 +2058,7 @@ export default () => ({ reportID: '6801643744224146', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: [ 'concierge@expensify.com', @@ -2090,7 +2090,7 @@ export default () => ({ reportID: '7658708888047100', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: [ 'concierge@expensify.com', @@ -2119,7 +2119,7 @@ export default () => ({ reportID: '7756405299640824', reportName: '#jackd23', chatType: 'policyRoom', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: 'C28C2634DD7226B8', participants: ['applausetester+pd1005@applause.expensifail.com'], isPinned: false, @@ -2141,7 +2141,7 @@ export default () => ({ reportID: '7819732651025410', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake5@gmail.com'], isPinned: false, @@ -2161,7 +2161,7 @@ export default () => ({ }, report_2543745284790730: { reportID: '2543745284790730', - ownerEmail: 'applausetester+perf2@applause.expensifail.com', + ownerAccountID: 17, managerEmail: 'fake6@gmail.com', currency: 'USD', chatReportID: '98817646', @@ -2174,7 +2174,7 @@ export default () => ({ }, report_4249286573496381: { reportID: '4249286573496381', - ownerEmail: 'applausetester+perf2@applause.expensifail.com', + ownerAccountID: 17, managerEmail: 'christoph+hightraffic@margelo.io', currency: 'USD', chatReportID: '4867098979334014', diff --git a/src/libs/E2E/apiMocks/openReport.js b/src/libs/E2E/apiMocks/openReport.js index 3eb9c7890299..75e0baea36a0 100644 --- a/src/libs/E2E/apiMocks/openReport.js +++ b/src/libs/E2E/apiMocks/openReport.js @@ -7,7 +7,7 @@ export default () => ({ reportID: '98345625', reportName: 'Chat Report', chatType: '', - ownerEmail: '__fake__', + ownerAccountID: 0, policyID: '_FAKE_', participants: ['fake1@gmail.com', 'fake2@gmail.com', 'fake3@gmail.com', 'fake4@gmail.com', 'fake5@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'], isPinned: false, diff --git a/src/libs/IOUUtils.js b/src/libs/IOUUtils.js index 371243345eb6..49bd29f05f6e 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: {ownerAccountID: user2, managerEmail: user1, total: $10 (a positive amount, owed to user2)} + * If user1 requests $17 from user2, then we have: {ownerAccountID: user1, managerEmail: 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/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 72f8f297344e..8344c5b9d25f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -62,7 +62,7 @@ const iouReports = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, callback: (report, key) => { - if (!report || !key || !report.ownerEmail) { + if (!report || !key || !report.ownerAccountID) { return; } @@ -423,7 +423,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { brickRoadIndicator: null, icons: null, tooltipText: null, - ownerEmail: null, + ownerAccountID: null, subtitle: null, participantsList: null, accountID: 0, @@ -467,7 +467,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { result.allReportErrors = getAllReportErrors(report, reportActions); result.brickRoadIndicator = !_.isEmpty(result.allReportErrors) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : null; - result.ownerEmail = report.ownerEmail; + result.ownerAccountID = report.ownerAccountID; result.reportID = report.reportID; result.isUnread = ReportUtils.isUnread(report); result.hasDraftComment = report.hasDraft; @@ -716,7 +716,7 @@ function getOptions( } const isCurrentUserOwnedPolicyExpenseChatThatCouldShow = - reportOption.isPolicyExpenseChat && reportOption.ownerEmail === currentUserLogin && includeOwnedWorkspaceChats && !reportOption.isArchivedRoom; + reportOption.isPolicyExpenseChat && reportOption.ownerAccountID === currentUserAccountID && includeOwnedWorkspaceChats && !reportOption.isArchivedRoom; // Skip if we aren't including multiple participant reports and this report has multiple participants if (!isCurrentUserOwnedPolicyExpenseChatThatCouldShow && !includeMultipleParticipantReports && !reportOption.login) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 4ddbf032867c..a4695c6c4d51 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -749,11 +749,10 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false, return [actorIcon]; } if (isTaskReport(report)) { - const ownerEmail = report.ownerEmail || ''; const ownerIcon = { id: report.ownerAccountID, source: UserUtils.getAvatar(lodashGet(personalDetails, [report.ownerAccountID, 'avatar']), report.ownerAccountID), - name: ownerEmail, + name: lodashGet(personalDetails, [report.ownerAccountID, 'login'], ''), type: CONST.ICON_TYPE_AVATAR, }; @@ -791,7 +790,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false, const adminIcon = { id: report.ownerAccountID, source: UserUtils.getAvatar(lodashGet(personalDetails, [report.ownerAccountID, 'avatar']), report.ownerAccountID), - name: report.ownerEmail, + name: lodashGet(personalDetails, [report.ownerAccountID, 'login'], ''), type: CONST.ICON_TYPE_AVATAR, }; @@ -806,7 +805,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 ? report.managerEmail : lodashGet(personalDetails, [report.ownerAccountID, 'login'], ''); const accountID = isPayer ? report.managerID : report.ownerAccountID; return [ { @@ -944,7 +943,7 @@ function getMoneyRequestTotal(report, moneyRequestReports = {}) { * @returns {String} */ function getPolicyExpenseChatName(report) { - const reportOwnerDisplayName = getDisplayNameForParticipant(report.ownerAccountID) || report.ownerEmail || report.reportName; + const reportOwnerDisplayName = getDisplayNameForParticipant(report.ownerAccountID) || lodashGet(allPersonalDetails, [report.ownerAccountID, 'login']) || report.reportName; // If the policy expense chat is owned by this user, use the name of the policy as the report name. if (report.isOwnPolicyExpenseChat) { diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index ee53cd9df69a..7373b5196412 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -234,7 +234,6 @@ function getOptionData(reportID) { brickRoadIndicator: null, icons: null, tooltipText: null, - ownerEmail: null, ownerAccountID: null, subtitle: null, participantsList: null, @@ -277,7 +276,6 @@ function getOptionData(reportID) { result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : null; result.allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions); result.brickRoadIndicator = !_.isEmpty(result.allReportErrors) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; - result.ownerEmail = report.ownerEmail; result.ownerAccountID = report.ownerAccountID; result.reportID = report.reportID; result.isUnread = ReportUtils.isUnread(report); diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 38638e22a464..54ab9c284dee 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -243,7 +243,7 @@ function setUpPoliciesAndNavigate(session) { // Approved Accountants and Guides can enter a flow where they make a workspace for other users, // and those are passed as a search parameter when using transition links - const ownerEmail = url.searchParams.get('ownerEmail'); + const policyOwnerEmail = url.searchParams.get('ownerEmail'); const makeMeAdmin = url.searchParams.get('makeMeAdmin'); const policyName = url.searchParams.get('policyName'); @@ -255,7 +255,7 @@ function setUpPoliciesAndNavigate(session) { const shouldCreateFreePolicy = !isLoggingInAsNewUser && isTransitioningFromOldDot && exitTo === ROUTES.WORKSPACE_NEW; if (shouldCreateFreePolicy) { - Policy.createWorkspace(ownerEmail, makeMeAdmin, policyName, true); + Policy.createWorkspace(policyOwnerEmail, makeMeAdmin, policyName, true); return; } if (!isLoggingInAsNewUser && exitTo) { diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index ddd0d872ce97..4437f9363514 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -16,7 +16,7 @@ let isReadyPromise = new Promise((resolve) => { let isFirstTimeNewExpensifyUser; let isLoadingReportData = true; -let email = ''; +let currentUserAccountID; /** * Check that a few requests have completed so that the welcome action can proceed: @@ -92,7 +92,7 @@ Onyx.connect({ return; } - email = val.email; + currentUserAccountID = val.accountID; }, }); @@ -119,7 +119,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) { const isDisplayingWorkspaceRoute = isWorkspaceRoute || exitingToWorkspaceRoute; // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one - const workspaceChatReport = _.find(allReports, (report) => ReportUtils.isPolicyExpenseChat(report) && report.ownerEmail === email && report.statusNum !== CONST.REPORT.STATUS.CLOSED); + const workspaceChatReport = _.find(allReports, (report) => ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED); if (workspaceChatReport && !isDisplayingWorkspaceRoute) { // This key is only updated when we call ReconnectApp, setting it to false now allows the user to navigate normally instead of always redirecting to the workspace chat Onyx.set(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, false); diff --git a/src/pages/iouReportPropTypes.js b/src/pages/iouReportPropTypes.js index d6481cb1e871..284f0915dbbc 100644 --- a/src/pages/iouReportPropTypes.js +++ b/src/pages/iouReportPropTypes.js @@ -11,7 +11,7 @@ export default PropTypes.shape({ total: PropTypes.number, /** The owner of the IOUReport */ - ownerEmail: PropTypes.string, + ownerAccountID: PropTypes.number, /** The currency of the IOUReport */ currency: PropTypes.string, diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index 4b50909032a1..f2e8578aaa38 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -50,9 +50,6 @@ export default PropTypes.shape({ /** The policy name to use for an archived report */ oldPolicyName: PropTypes.string, - /** The email address of the report owner */ - ownerEmail: PropTypes.string, - /** The accountID of the report owner */ ownerAccountID: PropTypes.number, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 75c7927888eb..d87a37c02e0e 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -283,7 +283,6 @@ describe('OptionsListUtils', () => { initialKeyStates: { [ONYXKEYS.SESSION]: {accountID: 2, email: 'tonystark@expensify.com'}, [`${ONYXKEYS.COLLECTION.REPORT}100`]: { - ownerEmail: 'mistersinister@marauders.com', ownerAccountID: 8, total: '1000', }, diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index f33fdc86ef77..5a0446dede65 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -232,7 +232,6 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID: policy.policyID, isOwnPolicyExpenseChat: true, - ownerEmail: 'ragnar@vikings.net', ownerAccountID: 1, }), ).toBe('Vikings Policy'); @@ -244,7 +243,6 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID: policy.policyID, isOwnPolicyExpenseChat: false, - ownerEmail: 'ragnar@vikings.net', ownerAccountID: 1, }), ).toBe('Ragnar Lothbrok'); @@ -254,7 +252,6 @@ describe('ReportUtils', () => { describe('Archived', () => { const baseArchivedPolicyExpenseChat = { chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - ownerEmail: 'ragnar@vikings.net', ownerAccountID: 1, policyID: policy.policyID, oldPolicyName: policy.name, From d5190dd7f2bed9cfbdc62cbdef238be68c4d15b2 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 6 Jul 2023 18:24:31 +0300 Subject: [PATCH 2/4] Update var name to be more clear --- src/libs/actions/Policy.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index bad48978b0e1..307181b28e89 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -821,15 +821,15 @@ function generatePolicyID() { /** * Optimistically creates a new workspace and default workspace chats * - * @param {String} [ownerEmail] Optional, the email of the account to make the owner of the policy + * @param {String} [policyOwnerEmail] Optional, the email of the account to make the owner of the policy * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy * @param {String} [policyName] Optional, custom policy name we will use for created workspace * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot * @returns {Promise} */ -function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false) { +function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false) { const policyID = generatePolicyID(); - const workspaceName = policyName || generateDefaultWorkspaceName(ownerEmail); + const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail); const { announceChatReportID, @@ -853,7 +853,7 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '', announceChatReportID, adminsChatReportID, expenseChatReportID, - ownerEmail, + ownerEmail: policyOwnerEmail, makeMeAdmin, policyName: workspaceName, type: CONST.POLICY.TYPE.FREE, From 0650ec3bf07a20001923ff35471de81c26cefec4 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 6 Jul 2023 18:29:37 +0300 Subject: [PATCH 3/4] Handle ownerAccountID being 0 --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ca52b20009ea..8b91aba3144c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -62,7 +62,7 @@ const iouReports = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, callback: (report, key) => { - if (!report || !key || !report.ownerAccountID) { + if (!report || !key || !_.isNumber(report.ownerAccountID)) { return; } From 8cae4230d96c3f35f99ebfd89740f872a47790bc Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 6 Jul 2023 18:49:22 +0300 Subject: [PATCH 4/4] Prettify long lines --- src/components/ReportWelcomeText.js | 3 ++- src/libs/actions/Welcome.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/ReportWelcomeText.js b/src/components/ReportWelcomeText.js index a08f01c91623..84ee3d73c874 100644 --- a/src/components/ReportWelcomeText.js +++ b/src/components/ReportWelcomeText.js @@ -73,7 +73,8 @@ function ReportWelcomeText(props) { {props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne')} {/* Use the policyExpenseChat owner's first name or their display name if it's undefined or an empty string */} - {lodashGet(props.personalDetails, [props.report.ownerAccountID, 'firstName']) || lodashGet(props.personalDetails, [props.report.ownerAccountID, 'displayName'], '')} + {lodashGet(props.personalDetails, [props.report.ownerAccountID, 'firstName']) || + lodashGet(props.personalDetails, [props.report.ownerAccountID, 'displayName'], '')} {props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')} {ReportUtils.getPolicyName(props.report)} diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index 4437f9363514..0a866e0c8c81 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -119,7 +119,10 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) { const isDisplayingWorkspaceRoute = isWorkspaceRoute || exitingToWorkspaceRoute; // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one - const workspaceChatReport = _.find(allReports, (report) => ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED); + const workspaceChatReport = _.find( + allReports, + (report) => ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED, + ); if (workspaceChatReport && !isDisplayingWorkspaceRoute) { // This key is only updated when we call ReconnectApp, setting it to false now allows the user to navigate normally instead of always redirecting to the workspace chat Onyx.set(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, false);