diff --git a/src/CONST.ts b/src/CONST.ts index 8134acabc0d7..2ae1a72acfc1 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5972,6 +5972,12 @@ const CONST = { HAS_CHILD_REPORT_AWAITING_ACTION: 'hasChildReportAwaitingAction', HAS_MISSING_INVOICE_BANK_ACCOUNT: 'hasMissingInvoiceBankAccount', }, + + RBR_REASONS: { + HAS_ERRORS: 'hasErrors', + HAS_VIOLATIONS: 'hasViolations', + HAS_TRANSACTION_THREAD_VIOLATIONS: 'hasTransactionThreadViolations', + }, } as const; type Country = keyof typeof CONST.ALL_COUNTRIES; diff --git a/src/languages/en.ts b/src/languages/en.ts index 2e543de3ae4b..b80ad5c7e5f3 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -5148,6 +5148,11 @@ const translations = { hasChildReportAwaitingAction: 'Has child report awaiting action', hasMissingInvoiceBankAccount: 'Has missing invoice bank account', }, + reasonRBR: { + hasErrors: 'Has errors in report or report actions data', + hasViolations: 'Has violations', + hasTransactionThreadViolations: 'Has transaction thread violations', + }, indicatorStatus: { theresAReportAwaitingAction: "There's a report awaiting action", theresAReportWithErrors: "There's a report with errors", diff --git a/src/languages/es.ts b/src/languages/es.ts index d719ef7c2e50..31dc7cd044e3 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -5664,6 +5664,11 @@ const translations = { hasChildReportAwaitingAction: 'Informe secundario pendiente de acción', hasMissingInvoiceBankAccount: 'Falta la cuenta bancaria de la factura', }, + reasonRBR: { + hasErrors: 'Tiene errores en los datos o las acciones del informe', + hasViolations: 'Tiene violaciones', + hasTransactionThreadViolations: 'Tiene violaciones de hilo de transacciones', + }, indicatorStatus: { theresAReportAwaitingAction: 'Hay un informe pendiente de acción', theresAReportWithErrors: 'Hay un informe con errores', diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index e7ad63467781..d63758761c3c 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -7,6 +7,7 @@ import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Beta, Policy, Report, ReportAction, ReportActions, TransactionViolation} from '@src/types/onyx'; import * as ReportUtils from './ReportUtils'; +import SidebarUtils from './SidebarUtils'; class NumberError extends SyntaxError { constructor() { @@ -645,13 +646,22 @@ function getReasonAndReportActionForGBRInLHNRow(report: OnyxEntry): GBRR return null; } +type RBRReasonAndReportAction = { + reason: TranslationPaths; + reportAction: OnyxEntry; +}; + /** * Gets the report action that is causing the RBR to show up in LHN */ -function getRBRReportAction(report: OnyxEntry, reportActions: OnyxEntry): OnyxEntry { - const {reportAction} = ReportUtils.getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions); +function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry, hasViolations: boolean): RBRReasonAndReportAction | null { + const {reason, reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ?? {}; - return reportAction; + if (reason) { + return {reason: `debug.reasonRBR.${reason}`, reportAction}; + } + + return null; } const DebugUtils = { @@ -673,7 +683,7 @@ const DebugUtils = { validateReportActionJSON, getReasonForShowingRowInLHN, getReasonAndReportActionForGBRInLHNRow, - getRBRReportAction, + getReasonAndReportActionForRBRInLHNRow, REPORT_ACTION_REQUIRED_PROPERTIES, REPORT_REQUIRED_PROPERTIES, }; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 944f703e96cb..a9cb79923a59 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -1,6 +1,7 @@ import {Str} from 'expensify-common'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import type {PolicySelector, ReportActionsSelector} from '@hooks/useReportIDs'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -222,10 +223,21 @@ function getOrderedReportIDs( return LHNReports; } -function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry, hasViolations: boolean, transactionViolations?: OnyxCollection) { - const hasErrors = Object.keys(ReportUtils.getAllReportErrors(report, reportActions)).length !== 0; +type ReasonAndReportActionThatHasRedBrickRoad = { + reason: ValueOf; + reportAction?: OnyxEntry; +}; +function getReasonAndReportActionThatHasRedBrickRoad( + report: Report, + reportActions: OnyxEntry, + hasViolations: boolean, + transactionViolations?: OnyxCollection, +): ReasonAndReportActionThatHasRedBrickRoad | null { + const {errors, reportAction} = ReportUtils.getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions); + const hasErrors = Object.keys(errors).length !== 0; const oneTransactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, ReportActionsUtils.getAllReportActions(report.reportID)); + if (oneTransactionThreadReportID) { const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID); @@ -236,11 +248,30 @@ function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry, hasViolations: boolean, transactionViolations?: OnyxCollection) { + return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations); } /** @@ -618,5 +649,6 @@ export default { getOptionData, getOrderedReportIDs, getWelcomeMessage, + getReasonAndReportActionThatHasRedBrickRoad, shouldShowRedBrickRoad, }; diff --git a/src/pages/Debug/Report/DebugReportActions.tsx b/src/pages/Debug/Report/DebugReportActions.tsx index e7c4059fffe7..3c08eb5bfdb1 100644 --- a/src/pages/Debug/Report/DebugReportActions.tsx +++ b/src/pages/Debug/Report/DebugReportActions.tsx @@ -37,10 +37,7 @@ function DebugReportActions({reportID}: DebugReportActionsProps) { ); return ( - +