From 61d6fcf64a5e6eb0a645fcfd4fa16a8b6388ddba Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 24 Jan 2024 12:08:27 +0100 Subject: [PATCH 1/4] feat: add offline handling for money reports with various currencies --- src/components/MoneyReportHeader.tsx | 3 +++ src/components/ReportActionItem/MoneyReportView.tsx | 3 ++- src/libs/ReportUtils.ts | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index afdc62218f95..d072dea34356 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -55,6 +55,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const reimbursableTotal = ReportUtils.getMoneyRequestReimbursableTotal(moneyRequestReport); const isApproved = ReportUtils.isReportApproved(moneyRequestReport); const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport); const policyType = policy?.type; const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(moneyRequestReport); @@ -140,6 +141,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt shouldShowApproveButton={shouldShowApproveButton} style={[styles.pv2]} formattedAmount={formattedAmount} + isDisabled={!canAllowSettlement} /> )} @@ -171,6 +173,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt shouldHidePaymentOptions={!shouldShowPayButton} shouldShowApproveButton={shouldShowApproveButton} formattedAmount={formattedAmount} + isDisabled={!canAllowSettlement} /> )} diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index 3d1710de1432..ecc5ef0df831 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -40,6 +40,7 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}: const {isSmallScreenWidth} = useWindowDimensions(); const {canUseReportFields} = usePermissions(); const isSettled = ReportUtils.isSettled(report.reportID); + const isTotalUpdated = ReportUtils.hasUpdatedTotal(report); const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(report); @@ -110,7 +111,7 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}: )} {formattedTotalAmount} diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 91fa7b35e824..10b7ce8965dd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4540,6 +4540,18 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry, repor return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat(reportAction, reportID); } +/** + * Check if money report has any transactions updated optimistically + */ +function hasUpdatedTotal(report: Report): boolean { + const transactions = TransactionUtils.getAllReportTransactions(report.reportID); + + const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); + const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency); + + return !(hasPendingTransaction && hasTransactionWithDifferentCurrency); +} + /** * Disable reply in thread action if: * @@ -4748,6 +4760,7 @@ export { doesReportBelongToWorkspace, getChildReportNotificationPreference, isReportFieldOfTypeTitle, + hasUpdatedTotal, }; export type { From aa34234694a467d0fbc637052a31960d1f107973 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 24 Jan 2024 16:05:50 +0100 Subject: [PATCH 2/4] fix: change the way settlement button on ReportPreview is handled --- src/components/ReportActionItem/ReportPreview.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 204c9b5e31d4..f6d8ba34a8bc 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -166,6 +166,8 @@ function ReportPreview(props) { const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(props.iouReport); const isApproved = ReportUtils.isReportApproved(props.iouReport); + const canAllowSettlement = ReportUtils.hasUpdatedTotal(props.iouReport); + console.log('%%%%%\n', 'canAllowSettlement: ', canAllowSettlement); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(props.iouReport); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID); const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; @@ -333,6 +335,7 @@ function ReportPreview(props) { horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, }} + isDisabled={!canAllowSettlement} /> )} {shouldShowSubmitButton && ( From 870502329845d9d031137c4968a0609a1037d14b Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 24 Jan 2024 16:13:20 +0100 Subject: [PATCH 3/4] fix: remove console logs --- src/components/ReportActionItem/ReportPreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index f6d8ba34a8bc..52847bf0366b 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -167,7 +167,6 @@ function ReportPreview(props) { const isApproved = ReportUtils.isReportApproved(props.iouReport); const canAllowSettlement = ReportUtils.hasUpdatedTotal(props.iouReport); - console.log('%%%%%\n', 'canAllowSettlement: ', canAllowSettlement); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(props.iouReport); const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID); const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; From 53dcfc1c0f8e38f60203a56e39f3278ba7b3d34c Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Sat, 3 Feb 2024 21:28:21 +0100 Subject: [PATCH 4/4] fix: remove empty line --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index af6c9372f27a..c3de0f9f749f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4657,7 +4657,6 @@ function hasUpdatedTotal(report: OnyxEntry): boolean { } const transactions = TransactionUtils.getAllReportTransactions(report.reportID); - const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency);