diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index f01fb049e943..8bd339f687b4 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -231,7 +231,7 @@ function MoneyRequestView({ } let receiptURIs; - const hasErrors = canEdit && TransactionUtils.hasMissingSmartscanFields(transaction); + const hasErrors = TransactionUtils.hasMissingSmartscanFields(transaction); if (hasReceipt) { receiptURIs = ReceiptUtils.getThumbnailAndImageURIs(transaction); } diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f321c10c686e..5a5405ee0565 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -528,14 +528,14 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< const parentReportAction: OnyxEntry = !report?.parentReportID || !report?.parentReportActionID ? null : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? ''] ?? null; - if (parentReportAction?.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { + if (ReportActionUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionUtils.isTransactionThread(parentReportAction)) { const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !ReportUtils.isSettled(transaction?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage'); } } else if ((ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { - if (ReportUtils.hasMissingSmartscanFields(report?.reportID ?? '') && !ReportUtils.isSettled(report?.reportID)) { + if (ReportUtils.shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '') && !ReportUtils.isSettled(report?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage'); } } else if (ReportUtils.hasSmartscanError(Object.values(reportActions ?? {}))) { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 75d8e22ac975..7acec4d8d8de 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1233,6 +1233,13 @@ function isLinkedTransactionHeld(reportActionID: string, reportID: string): bool return TransactionUtils.isOnHoldByTransactionID(getLinkedTransactionID(reportActionID, reportID) ?? ''); } +/** + * Check if the current user is the requestor of the action + */ +function wasActionTakenByCurrentUser(reportAction: OnyxEntry): boolean { + return currentUserAccountID === reportAction?.actorAccountID; +} + export { extractLinksFromMessageHtml, getDismissedViolationMessageText, @@ -1299,7 +1306,9 @@ export { isActionableJoinRequest, isActionableJoinRequestPending, isActionableTrackExpense, + getAllReportActions, isLinkedTransactionHeld, + wasActionTakenByCurrentUser, isResolvedActionTrackExpense, }; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 03538dc7a860..e0131b6a1f0f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2741,14 +2741,6 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio return transactionsWithReceipts.every((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)); } -/** - * Check if any of the transactions in the report has required missing fields - * - */ -function hasMissingSmartscanFields(iouReportID: string): boolean { - return TransactionUtils.getAllReportTransactions(iouReportID).some((transaction) => TransactionUtils.hasMissingSmartscanFields(transaction)); -} - /** * Get the transactions related to a report preview with receipts * Get the details linked to the IOU reportAction @@ -2765,6 +2757,33 @@ function getLinkedTransaction(reportAction: OnyxEntry { + if (!ReportActionsUtils.isMoneyRequestAction(action)) { + return false; + } + const transaction = getLinkedTransaction(action); + if (isEmptyObject(transaction)) { + return false; + } + if (!ReportActionsUtils.wasActionTakenByCurrentUser(action)) { + return false; + } + return TransactionUtils.hasMissingSmartscanFields(transaction); + }); +} + /** * Given a parent IOU report action get report name for the LHN. */ @@ -6250,7 +6269,7 @@ function hasSmartscanError(reportActions: ReportAction[]) { return false; } const IOUReportID = ReportActionsUtils.getIOUReportIDFromReportActionPreview(action); - const isReportPreviewError = ReportActionsUtils.isReportPreviewAction(action) && hasMissingSmartscanFields(IOUReportID) && !isSettled(IOUReportID); + const isReportPreviewError = ReportActionsUtils.isReportPreviewAction(action) && shouldShowRBRForMissingSmartscanFields(IOUReportID) && !isSettled(IOUReportID); 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); @@ -7014,6 +7033,7 @@ export { shouldReportBeInOptionList, shouldReportShowSubscript, shouldShowFlagComment, + shouldShowRBRForMissingSmartscanFields, shouldUseFullTitleToDisplay, sortReportsByLastRead, updateOptimisticParentReportAction,