From 49edb0fb51fce4bbf65e9b488a1fa29c78532073 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 28 Jul 2023 15:03:33 -0600 Subject: [PATCH 1/5] update condition to show settlement button --- src/components/MoneyReportHeader.js | 2 +- src/components/MoneyRequestDetails.js | 2 +- src/components/ReportActionItem/ReportPreview.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 01b0418c6ea8..f48b5c38763a 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -57,7 +57,7 @@ function MoneyReportHeader(props) { const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; const isPayer = Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); - const shouldShowSettlementButton = !isSettled && isPayer && !moneyRequestReport.isWaitingOnBankAccount; + const shouldShowSettlementButton = !isSettled && isPayer && !moneyRequestReport.isWaitingOnBankAccount && props.report.total !== 0; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress'])); const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency); diff --git a/src/components/MoneyRequestDetails.js b/src/components/MoneyRequestDetails.js index 5bb7c029d44b..2a5b04f336f9 100644 --- a/src/components/MoneyRequestDetails.js +++ b/src/components/MoneyRequestDetails.js @@ -89,7 +89,7 @@ function MoneyRequestDetails(props) { : UserUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'avatar']), moneyRequestReport.managerID); const isPayer = Policy.isAdminOfFreePolicy([props.policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); - const shouldShowSettlementButton = moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount; + const shouldShowSettlementButton = moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && moneyRequestReport.total !== 0; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.ownerAccountID, 'payPalMeAddress'])); let description = `${props.translate('iou.amount')} • ${props.translate('iou.cash')}`; diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index a67f2a293460..892241305d82 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -113,7 +113,7 @@ function ReportPreview(props) { const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const previewMessage = props.translate(ReportUtils.isSettled(props.iouReportID) || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName}); - + const shouldShowSettlementButton = !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && props.iouReport.total !== 0; return ( - {!_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && ( + {shouldShowSettlementButton && ( Date: Fri, 28 Jul 2023 15:13:43 -0600 Subject: [PATCH 2/5] fix style --- src/components/MoneyRequestDetails.js | 3 ++- src/components/ReportActionItem/ReportPreview.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyRequestDetails.js b/src/components/MoneyRequestDetails.js index 2a5b04f336f9..98c1ba5a3009 100644 --- a/src/components/MoneyRequestDetails.js +++ b/src/components/MoneyRequestDetails.js @@ -89,7 +89,8 @@ function MoneyRequestDetails(props) { : UserUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'avatar']), moneyRequestReport.managerID); const isPayer = Policy.isAdminOfFreePolicy([props.policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); - const shouldShowSettlementButton = moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && moneyRequestReport.total !== 0; + const shouldShowSettlementButton = + moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && moneyRequestReport.total !== 0; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.ownerAccountID, 'payPalMeAddress'])); let description = `${props.translate('iou.amount')} • ${props.translate('iou.cash')}`; diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 892241305d82..8df243c434b9 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -113,7 +113,8 @@ function ReportPreview(props) { const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const previewMessage = props.translate(ReportUtils.isSettled(props.iouReportID) || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName}); - const shouldShowSettlementButton = !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && props.iouReport.total !== 0; + const shouldShowSettlementButton = + !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && props.iouReport.total !== 0; return ( Date: Mon, 31 Jul 2023 15:38:21 -0600 Subject: [PATCH 3/5] use getMoneyRequestTotal --- src/components/MoneyReportHeader.js | 5 +++-- src/components/MoneyRequestDetails.js | 5 +++-- src/components/ReportActionItem/ReportPreview.js | 2 +- src/libs/actions/User.js | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index f48b5c38763a..71ac5e02467b 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -57,10 +57,11 @@ function MoneyReportHeader(props) { const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; const isPayer = Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); - const shouldShowSettlementButton = !isSettled && isPayer && !moneyRequestReport.isWaitingOnBankAccount && props.report.total !== 0; + const reportTotal = ReportUtils.getMoneyRequestTotal(props.report); + const shouldShowSettlementButton = !isSettled && isPayer && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress'])); - const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency); + const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.report.currency); return ( diff --git a/src/components/MoneyRequestDetails.js b/src/components/MoneyRequestDetails.js index 98c1ba5a3009..a690c31c000c 100644 --- a/src/components/MoneyRequestDetails.js +++ b/src/components/MoneyRequestDetails.js @@ -79,7 +79,8 @@ function MoneyRequestDetails(props) { const transactionDate = lodashGet(props.parentReportAction, ['created']); const formattedTransactionDate = DateUtils.getDateStringFromISOTimestamp(transactionDate); - const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency); + const reportTotal = ReportUtils.getMoneyRequestTotal(props.report); + const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.report.currency); const moneyRequestReport = props.isSingleTransactionView ? props.parentReport : props.report; const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); const isExpenseReport = ReportUtils.isExpenseReport(moneyRequestReport); @@ -90,7 +91,7 @@ function MoneyRequestDetails(props) { const isPayer = Policy.isAdminOfFreePolicy([props.policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); const shouldShowSettlementButton = - moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && moneyRequestReport.total !== 0; + moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.ownerAccountID, 'payPalMeAddress'])); let description = `${props.translate('iou.amount')} • ${props.translate('iou.cash')}`; diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 8df243c434b9..71e5a7f712b2 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -114,7 +114,7 @@ function ReportPreview(props) { const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const previewMessage = props.translate(ReportUtils.isSettled(props.iouReportID) || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName}); const shouldShowSettlementButton = - !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && props.iouReport.total !== 0; + !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && reportAmount !== 0; return ( { + console.log('over here', pushJSON) SequentialQueue.getCurrentRequest().then(() => { // If we don't have the currentUserAccountID (user is logged out) we don't want to update Onyx with data from Pusher if (!currentUserAccountID) { From 4249cdf51c5cfb2e77127f18c57400a465c4f1b9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 31 Jul 2023 15:40:26 -0600 Subject: [PATCH 4/5] rm log --- src/libs/actions/User.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 0b027fc6d181..f6652bdf8fa2 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -563,7 +563,6 @@ function subscribeToUserEvents() { // Handles Onyx updates coming from Pusher through the mega multipleEvents. PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON) => { - console.log('over here', pushJSON) SequentialQueue.getCurrentRequest().then(() => { // If we don't have the currentUserAccountID (user is logged out) we don't want to update Onyx with data from Pusher if (!currentUserAccountID) { From 2f8c3ed1864f7c081ab88a6a4a490a90ac453650 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 31 Jul 2023 17:00:51 -0600 Subject: [PATCH 5/5] use correct total --- src/components/ReportActionItem/ReportPreview.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 71e5a7f712b2..d5d85df5e7ee 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -95,17 +95,18 @@ const defaultProps = { function ReportPreview(props) { const managerID = props.iouReport.managerID || props.action.actorAccountID || 0; const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID'); - let reportAmount = ReportUtils.getMoneyRequestTotal(props.iouReport); - if (reportAmount) { - reportAmount = CurrencyUtils.convertToDisplayString(reportAmount, props.iouReport.currency); + const reportTotal = ReportUtils.getMoneyRequestTotal(props.iouReport); + let displayAmount; + if (reportTotal) { + displayAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.iouReport.currency); } else { // If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere") - reportAmount = ''; + displayAmount = ''; const actionMessage = lodashGet(props.action, ['message', 0, 'text'], ''); const splits = actionMessage.split(' '); for (let i = 0; i < splits.length; i++) { if (/\d/.test(splits[i])) { - reportAmount = splits[i]; + displayAmount = splits[i]; } } } @@ -114,7 +115,7 @@ function ReportPreview(props) { const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const previewMessage = props.translate(ReportUtils.isSettled(props.iouReportID) || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName}); const shouldShowSettlementButton = - !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && reportAmount !== 0; + !_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && reportTotal !== 0; return ( - {reportAmount} + {displayAmount} {ReportUtils.isSettled(props.iouReportID) && (