diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 7391b8ccd933..4e94a9afe018 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -34,6 +34,7 @@ import useThemeStyles from '@styles/useThemeStyles'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; +import * as Localize from '@src/libs/Localize'; import ONYXKEYS from '@src/ONYXKEYS'; import ReportActionItemImages from './ReportActionItemImages'; @@ -234,6 +235,10 @@ function MoneyRequestPreview(props) { return props.translate('iou.receiptScanning'); } + if (TransactionUtils.hasMissingSmartscanFields(props.transaction)) { + return Localize.translateLocal('iou.receiptMissingDetails'); + } + return CurrencyUtils.convertToDisplayString(requestAmount, requestCurrency); }; diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 4678ce395f76..13586b6c5d2e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -357,6 +357,8 @@ function getAllReportErrors(report, reportActions) { if (ReportUtils.hasMissingSmartscanFields(report.reportID) && !ReportUtils.isSettled(report.reportID)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } + } else if (ReportUtils.hasSmartscanError(_.values(reportActions))) { + _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } // All error objects related to the report. Each object in the sources contains error messages keyed by microtime diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1266f145de30..83618b8b6731 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -421,6 +421,19 @@ Onyx.connect({ }, }); +let allTransactions: OnyxCollection = {}; + +Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (value) => { + if (!value) { + return; + } + allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction)); + }, +}); + function getPolicyTags(policyID: string) { return allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {}; } @@ -898,8 +911,8 @@ function hasSingleParticipant(report: OnyxEntry): boolean { * */ function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined): boolean { - const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); + const transactions = TransactionUtils.getAllReportTransactions(iouReportID); + return transactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); } /** @@ -1588,8 +1601,8 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData * */ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactions.filter((transaction) => transaction.reimbursable === false).length > 0; + const transactions = TransactionUtils.getAllReportTransactions(iouReportID); + return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { @@ -1841,8 +1854,8 @@ function canEditReportAction(reportAction: OnyxEntry): boolean { * Gets all transactions on an IOU report with a receipt */ function getTransactionsWithReceipts(iouReportID: string | undefined): Transaction[] { - const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactions.filter((transaction) => TransactionUtils.hasReceipt(transaction)); + const transactions = TransactionUtils.getAllReportTransactions(iouReportID); + return transactions.filter((transaction) => TransactionUtils.hasReceipt(transaction)); } /** @@ -1934,6 +1947,10 @@ function getReportPreviewMessage( return Localize.translateLocal('iou.receiptScanning'); } + if (TransactionUtils.hasMissingSmartscanFields(linkedTransaction)) { + return Localize.translateLocal('iou.receiptMissingDetails'); + } + const transactionDetails = getTransactionDetails(linkedTransaction); const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency ?? ''); return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment: transactionDetails?.comment ?? ''}); @@ -4251,6 +4268,22 @@ function getRoom(type: ValueOf, policyID: string) function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry): boolean { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } +/** + * Checks if report action has error when smart scanning + */ +function hasSmartscanError(reportActions: ReportAction[]) { + return reportActions.some((action) => { + if (!ReportActionsUtils.isSplitBillAction(action) && !ReportActionsUtils.isReportPreviewAction(action)) { + return false; + } + const isReportPreviewError = ReportActionsUtils.isReportPreviewAction(action) && hasMissingSmartscanFields(ReportActionsUtils.getIOUReportIDFromReportActionPreview(action)); + const transactionID = (action.originalMessage as IOUMessage).IOUTransactionID ?? '0'; + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {}; + const isSplitBillError = ReportActionsUtils.isSplitBillAction(action) && TransactionUtils.hasMissingSmartscanFields(transaction as Transaction); + + return isReportPreviewError || isSplitBillError; + }); +} function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean { if (event.key.length > 1) { @@ -4451,6 +4484,7 @@ export { shouldDisableWelcomeMessage, navigateToPrivateNotes, canEditWriteCapability, + hasSmartscanError, shouldAutoFocusOnKeyPress, };