From a4cadc49a5762cab8447c19513ce082206514b60 Mon Sep 17 00:00:00 2001 From: Mahesh Date: Fri, 20 Oct 2023 20:42:47 +0530 Subject: [PATCH 01/11] add gbr to pending wallet reports & update perview for 1:1 reports with iou --- src/libs/OptionsListUtils.js | 4 +++- src/libs/ReportUtils.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 75806077daca..f03ee3a58fef 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -398,7 +398,9 @@ function getLastMessageTextForReport(report) { reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && ReportActionUtils.isMoneyRequestAction(reportAction), ); - lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true); + // Weather parent report is a 1:1 report + const isChatReport = ReportUtils.isChatReport(report); + lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, isChatReport); } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); } else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 75ee6257caab..213c6f5e5fb4 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -272,14 +272,15 @@ function sortReportsByLastRead(reports) { * Whether the Money Request report is settled * * @param {String} reportID + * @param {Boolean} isReportFromChat * @returns {Boolean} */ -function isSettled(reportID) { +function isSettled(reportID, isReportFromChat) { if (!allReports) { return false; } const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] || {}; - if ((typeof report === 'object' && Object.keys(report).length === 0) || report.isWaitingOnBankAccount) { + if ((typeof report === 'object' && Object.keys(report).length === 0) || (report.isWaitingOnBankAccount && !isReportFromChat)) { return false; } @@ -1295,7 +1296,8 @@ function isWaitingForIOUActionFromCurrentUser(report) { } // Money request waiting for current user to add their credit bank account - if (report.hasOutstandingIOU && report.ownerAccountID === currentUserAccountID && report.isWaitingOnBankAccount) { + // hasOutstandingIOU will be false if the user paid, but isWaitingOnBankAccount will be true if user don't have a wallet setup + if ((report.hasOutstandingIOU || report.isWaitingOnBankAccount) && report.ownerAccountID === currentUserAccountID) { return true; } @@ -1615,9 +1617,10 @@ function getTransactionReportName(reportAction) { * @param {Object} report * @param {Object} [reportAction={}] This can be either a report preview action or the IOU action * @param {Boolean} [shouldConsiderReceiptBeingScanned=false] + * @param {Boolean} isReportFromChat If the report is from 1:1 chat * @returns {String} */ -function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false) { +function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isReportFromChat = false) { const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); if (_.isEmpty(report) || !report.reportID) { @@ -1656,7 +1659,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip } } - if (isSettled(report.reportID)) { + if (isSettled(report.reportID, isReportFromChat)) { // A settled report preview message can come in three formats "paid ... elsewhere" or "paid ... with Expensify" let translatePhraseKey = 'iou.paidElsewhereWithAmount'; if ( From 7640d98b61e3e5483c69294dfc49bb649c2c151a Mon Sep 17 00:00:00 2001 From: Mahesh Date: Sat, 21 Oct 2023 00:38:52 +0530 Subject: [PATCH 02/11] update test case --- tests/unit/ReportUtilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index 6d3aba1fd9ad..d164036d4caf 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -271,16 +271,16 @@ describe('ReportUtils', () => { expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false); }); }); - it('returns false when the report has no oustanding IOU but is waiting for a bank account and the logged user is the report owner', () => { + it('returns true when the report has no outstanding IOU but is waiting for a bank account and the logged user is the report owner', () => { const report = { ...LHNTestUtils.getFakeReport(), hasOutstandingIOU: false, ownerAccountID: currentUserAccountID, isWaitingOnBankAccount: true, }; - expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false); + expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true); }); - it('returns true when the report has oustanding IOU and is waiting for a bank account and the logged user is the report owner', () => { + it('returns true when the report has outstanding IOU and is waiting for a bank account and the logged user is the report owner', () => { const report = { ...LHNTestUtils.getFakeReport(), hasOutstandingIOU: true, From 19038ac1704377f95c190f36c870688b0300fe4b Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 13:26:41 +0530 Subject: [PATCH 03/11] add preview message for ReimbursementQueued action & unit test fixes --- src/libs/OptionsListUtils.js | 2 ++ src/libs/ReportActionsUtils.ts | 5 +++++ src/libs/ReportUtils.js | 24 +++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f03ee3a58fef..8292c9ac9c3f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -401,6 +401,8 @@ function getLastMessageTextForReport(report) { // Weather parent report is a 1:1 report const isChatReport = ReportUtils.isChatReport(report); lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, isChatReport); + } else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) { + lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report); } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); } else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index d016e220e147..b17b403ee8ef 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -91,6 +91,10 @@ function isWhisperAction(reportAction: OnyxEntry): boolean { return (reportAction?.whisperedToAccountIDs ?? []).length > 0; } +function isReimbursementQueuedAction(reportAction: OnyxEntry) { + return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED; +} + /** * Returns whether the comment is a thread parent message/the first message in a thread */ @@ -636,6 +640,7 @@ export { isThreadParentMessage, isTransactionThread, isWhisperAction, + isReimbursementQueuedAction, shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 12d4a71f964d..689be5c7678c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -284,7 +284,8 @@ function isSettled(reportID, isReportFromChat) { return false; } - return report.statusNum === CONST.REPORT.STATUS.REIMBURSED; + // APPROVED status is for Personal policies + return report.statusNum === CONST.REPORT.STATUS.REIMBURSED || report.statusNum === CONST.REPORT.STATUS.APPROVED; } /** @@ -1241,6 +1242,26 @@ function getDeletedParentActionMessageForChatReport(reportAction) { return deletedMessageText; } +/** + * Returns the preview message for `REIMBURSEMENTQUEUED` action + * + * @param {Object} reportAction + * @param {Object} report + * @returns {String} + */ + +function getReimbursementQueuedActionMessage(reportAction, report) { + const submitterDisplayName = getDisplayNameForParticipant(report.ownerAccountID, true); + let messageKey; + if (lodashGet(reportAction, 'originalMessage.paymentType', '') === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { + messageKey = 'iou.waitingOnEnabledWallet'; + } else { + messageKey = 'iou.waitingOnBankAccount'; + } + + return Localize.translateLocal(messageKey, {submitterDisplayName}); +} + /** * Returns the last visible message for a given report after considering the given optimistic actions * @@ -4125,4 +4146,5 @@ export { isReportDraft, shouldUseFullTitleToDisplay, parseReportRouteParams, + getReimbursementQueuedActionMessage, }; From d9ce1d48c8527f0df16c2fb7748870af3f37e2bc Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 13:46:15 +0530 Subject: [PATCH 04/11] fix typos & suggestions --- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 8292c9ac9c3f..0393884e63a0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -398,7 +398,7 @@ function getLastMessageTextForReport(report) { reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && ReportActionUtils.isMoneyRequestAction(reportAction), ); - // Weather parent report is a 1:1 report + // Whether parent report is a 1:1 report const isChatReport = ReportUtils.isChatReport(report); lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, isChatReport); } else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 689be5c7678c..acfd4bd53527 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -272,15 +272,14 @@ function sortReportsByLastRead(reports) { * Whether the Money Request report is settled * * @param {String} reportID - * @param {Boolean} isReportFromChat * @returns {Boolean} */ -function isSettled(reportID, isReportFromChat) { +function isSettled(reportID) { if (!allReports) { return false; } const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] || {}; - if ((typeof report === 'object' && Object.keys(report).length === 0) || (report.isWaitingOnBankAccount && !isReportFromChat)) { + if (typeof report === 'object' && Object.keys(report).length === 0) { return false; } @@ -1317,7 +1316,7 @@ function isWaitingForIOUActionFromCurrentUser(report) { } // Money request waiting for current user to add their credit bank account - // hasOutstandingIOU will be false if the user paid, but isWaitingOnBankAccount will be true if user don't have a wallet setup + // hasOutstandingIOU will be false if the user paid, but isWaitingOnBankAccount will be true if user don't have a wallet or bank account setup if ((report.hasOutstandingIOU || report.isWaitingOnBankAccount) && report.ownerAccountID === currentUserAccountID) { return true; } @@ -1638,10 +1637,10 @@ function getTransactionReportName(reportAction) { * @param {Object} report * @param {Object} [reportAction={}] This can be either a report preview action or the IOU action * @param {Boolean} [shouldConsiderReceiptBeingScanned=false] - * @param {Boolean} isReportFromChat If the report is from 1:1 chat + * @param {Boolean} isPreviewMessageForParentChatReport If the report is from 1:1 chat * @returns {String} */ -function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isReportFromChat = false) { +function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isPreviewMessageForParentChatReport = false) { const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); if (_.isEmpty(report) || !report.reportID) { @@ -1680,7 +1679,8 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip } } - if (isSettled(report.reportID, isReportFromChat)) { + // Show Paid preview message if it's settled or if the amount is paid & stuck at receivers end for only chat reports. + if (isSettled(report.reportID) || (report.isWaitingOnBankAccount && !isPreviewMessageForParentChatReport)) { // A settled report preview message can come in three formats "paid ... elsewhere" or "paid ... with Expensify" let translatePhraseKey = 'iou.paidElsewhereWithAmount'; if ( From 07492fc0e398a2c585f6d6d24e8ac1f0742062db Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 15:12:48 +0530 Subject: [PATCH 05/11] update condition to show paid --- 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 acfd4bd53527..6180e84787c1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -279,7 +279,7 @@ function isSettled(reportID) { return false; } const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] || {}; - if (typeof report === 'object' && Object.keys(report).length === 0) { + if ((typeof report === 'object' && Object.keys(report).length === 0) || report.isWaitingOnBankAccount) { return false; } @@ -1680,7 +1680,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip } // Show Paid preview message if it's settled or if the amount is paid & stuck at receivers end for only chat reports. - if (isSettled(report.reportID) || (report.isWaitingOnBankAccount && !isPreviewMessageForParentChatReport)) { + if (isSettled(report.reportID) || (report.isWaitingOnBankAccount && isPreviewMessageForParentChatReport)) { // A settled report preview message can come in three formats "paid ... elsewhere" or "paid ... with Expensify" let translatePhraseKey = 'iou.paidElsewhereWithAmount'; if ( From f233987ecdcc7cc223dd5708c9d254d5308217cb Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 15:20:09 +0530 Subject: [PATCH 06/11] fix typo --- 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 6180e84787c1..26e9cec6c9b2 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -283,7 +283,7 @@ function isSettled(reportID) { return false; } - // APPROVED status is for Personal policies + // APPROVED status is for free group policy return report.statusNum === CONST.REPORT.STATUS.REIMBURSED || report.statusNum === CONST.REPORT.STATUS.APPROVED; } From 14ff18da9ff5ebf0599c5d6317e5a42a2f47dabf Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 15:40:18 +0530 Subject: [PATCH 07/11] fix suggestions --- src/libs/OptionsListUtils.js | 4 +--- src/libs/ReportUtils.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0393884e63a0..e909f0d86453 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -398,9 +398,7 @@ function getLastMessageTextForReport(report) { reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && ReportActionUtils.isMoneyRequestAction(reportAction), ); - // Whether parent report is a 1:1 report - const isChatReport = ReportUtils.isChatReport(report); - lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, isChatReport); + lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, ReportUtils.isChatReport(report)); } else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report); } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 26e9cec6c9b2..2df4362b3e45 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1637,7 +1637,7 @@ function getTransactionReportName(reportAction) { * @param {Object} report * @param {Object} [reportAction={}] This can be either a report preview action or the IOU action * @param {Boolean} [shouldConsiderReceiptBeingScanned=false] - * @param {Boolean} isPreviewMessageForParentChatReport If the report is from 1:1 chat + * @param {Boolean} isPreviewMessageForParentChatReport * @returns {String} */ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isPreviewMessageForParentChatReport = false) { From f08eeae308675f4ea483910d0ce01d3694444863 Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 17:30:48 +0530 Subject: [PATCH 08/11] fix paid message for ws --- src/libs/ReportUtils.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 2df4362b3e45..a8f62837a868 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -283,8 +283,13 @@ function isSettled(reportID) { return false; } - // APPROVED status is for free group policy - return report.statusNum === CONST.REPORT.STATUS.REIMBURSED || report.statusNum === CONST.REPORT.STATUS.APPROVED; + // In case the payment is scheduled and we are waiting for the payee to set up their walled, + // consider the report as paid as well. + if (report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS.APPROVED) { + return true; + } + + return report.statusNum === CONST.REPORT.STATUS.REIMBURSED; } /** @@ -1685,7 +1690,8 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip let translatePhraseKey = 'iou.paidElsewhereWithAmount'; if ( _.contains([CONST.IOU.PAYMENT_TYPE.VBBA, CONST.IOU.PAYMENT_TYPE.EXPENSIFY], lodashGet(reportAction, 'originalMessage.paymentType')) || - reportActionMessage.match(/ (with Expensify|using Expensify)$/) + reportActionMessage.match(/ (with Expensify|using Expensify)$/) || + report.isWaitingOnBankAccount ) { translatePhraseKey = 'iou.paidWithExpensifyWithAmount'; } From 42ebd89b2d3597b54b00c87629d7aed40374bdc2 Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 18:41:16 +0530 Subject: [PATCH 09/11] update condition to show GBR only on pay --- 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 3cf45952ed1e..85ca21931b9e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1322,7 +1322,7 @@ function isWaitingForIOUActionFromCurrentUser(report) { // Money request waiting for current user to add their credit bank account // hasOutstandingIOU will be false if the user paid, but isWaitingOnBankAccount will be true if user don't have a wallet or bank account setup - if ((report.hasOutstandingIOU || report.isWaitingOnBankAccount) && report.ownerAccountID === currentUserAccountID) { + if (!report.hasOutstandingIOU && report.isWaitingOnBankAccount && report.ownerAccountID === currentUserAccountID) { return true; } From 11fc844251634140fa9c78dff7155e31a4a0e34e Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 18:56:29 +0530 Subject: [PATCH 10/11] fix tests failing --- tests/unit/ReportUtilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index d164036d4caf..25f093cbd711 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -280,14 +280,14 @@ describe('ReportUtils', () => { }; expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true); }); - it('returns true when the report has outstanding IOU and is waiting for a bank account and the logged user is the report owner', () => { + it('returns false when the report has outstanding IOU and is not waiting for a bank account and the logged user is the report owner', () => { const report = { ...LHNTestUtils.getFakeReport(), hasOutstandingIOU: true, ownerAccountID: currentUserAccountID, - isWaitingOnBankAccount: true, + isWaitingOnBankAccount: false, }; - expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true); + expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false); }); it('returns false when the report has no oustanding IOU but is waiting for a bank account and the logged user is not the report owner', () => { const report = { From ceb319fc92f4d2984469f6cac6aa0d01cbaf75fa Mon Sep 17 00:00:00 2001 From: Mahesh Vagicherla Date: Mon, 23 Oct 2023 19:10:28 +0530 Subject: [PATCH 11/11] fix typos --- src/libs/ReportUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 85ca21931b9e..5122a8177421 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -283,7 +283,7 @@ function isSettled(reportID) { return false; } - // In case the payment is scheduled and we are waiting for the payee to set up their walled, + // In case the payment is scheduled and we are waiting for the payee to set up their wallet, // consider the report as paid as well. if (report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS.APPROVED) { return true; @@ -1253,7 +1253,6 @@ function getDeletedParentActionMessageForChatReport(reportAction) { * @param {Object} report * @returns {String} */ - function getReimbursementQueuedActionMessage(reportAction, report) { const submitterDisplayName = getDisplayNameForParticipant(report.ownerAccountID, true); let messageKey;