From 6b41a1cbd1ab273021e4a34efea1d1fd8a8dbffe Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 09:00:02 -0600 Subject: [PATCH 1/8] change errors key --- src/libs/SearchUIUtils.ts | 2 +- src/types/onyx/SearchResults.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 68b3ce60963a..44ffe58578ae 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -264,7 +264,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr // We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (transaction?.hasError || report.hasError) { + if (transaction?.errors || report?.errors) { return CONST.SEARCH.ACTION_TYPES.REVIEW; } diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 4197fa402530..99ca6eaef909 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -6,6 +6,7 @@ import type TransactionListItem from '@components/SelectionList/Search/Transacti import type {ReportActionListItemType, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; import type CONST from '@src/CONST'; import type ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxCommon from './OnyxCommon'; import type {ACHAccount, ApprovalRule, ExpenseRule} from './Policy'; import type {InvoiceReceiver, Participants} from './Report'; import type ReportActionName from './ReportActionName'; @@ -156,7 +157,7 @@ type SearchReport = { isActionLoading?: boolean; /** Whether the report has violations or errors */ - hasError?: boolean; + errors?: OnyxCommon.Errors; /** Collection of report participants, indexed by their accountID */ participants?: Participants; @@ -367,7 +368,7 @@ type SearchTransaction = { isActionLoading?: boolean; /** Whether the transaction has violations or errors */ - hasError?: boolean; + errors?: OnyxCommon.Errors | null; }; /** Types of searchable transactions */ From ff9b94309e21c167b43c4aa2d103b08ef22aa816 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 09:07:58 -0600 Subject: [PATCH 2/8] fix lint --- src/libs/actions/Search.ts | 5 +++-- src/types/onyx/SearchResults.ts | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 8ef5802b80dc..b4a64d6c5d10 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -8,6 +8,7 @@ import * as API from '@libs/API'; import type {ExportSearchItemsToCSVParams, SubmitReportParams} from '@libs/API/parameters'; import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ApiUtils from '@libs/ApiUtils'; +import * as ErrorUtils from '@libs/ErrorUtils'; import fileDownload from '@libs/fileDownload'; import enhanceParameters from '@libs/Network/enhanceParameters'; import {rand64} from '@libs/NumberUtils'; @@ -285,7 +286,7 @@ function approveMoneyRequestOnSearch(hash: number, reportIDList: string[], trans }, ]; const optimisticData: OnyxUpdate[] = createOnyxData({isActionLoading: true}); - const failureData: OnyxUpdate[] = createOnyxData({hasError: true}); + const failureData: OnyxUpdate[] = createOnyxData({errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}); const finallyData: OnyxUpdate[] = createOnyxData({isActionLoading: false}); API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH, {hash, reportIDList}, {optimisticData, failureData, finallyData}); @@ -305,7 +306,7 @@ function payMoneyRequestOnSearch(hash: number, paymentData: PaymentData[], trans ]; const optimisticData: OnyxUpdate[] = createOnyxData({isActionLoading: true}); - const failureData: OnyxUpdate[] = createOnyxData({hasError: true}); + const failureData: OnyxUpdate[] = createOnyxData({errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}); const finallyData: OnyxUpdate[] = createOnyxData({isActionLoading: false}); // eslint-disable-next-line rulesdir/no-api-side-effects-method diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 99ca6eaef909..a0da40411724 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -159,6 +159,9 @@ type SearchReport = { /** Whether the report has violations or errors */ errors?: OnyxCommon.Errors; + /** Whether the transaction has violations or errors */ + hasErrors?: boolean; + /** Collection of report participants, indexed by their accountID */ participants?: Participants; }; @@ -368,7 +371,10 @@ type SearchTransaction = { isActionLoading?: boolean; /** Whether the transaction has violations or errors */ - errors?: OnyxCommon.Errors | null; + hasErrors?: boolean; + + /** Whether the transaction has violations or errors */ + errors?: OnyxCommon.Errors; }; /** Types of searchable transactions */ From 8ba794f53a28f4965d00ab20576382dc82753e89 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 09:09:40 -0600 Subject: [PATCH 3/8] support both errors temporarily --- src/libs/SearchUIUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 44ffe58578ae..7f52f9dc0126 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -264,7 +264,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr // We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (transaction?.errors || report?.errors) { + if (transaction?.errors || transaction?.hasErrors || report?.errors || report?.hasErrors) { return CONST.SEARCH.ACTION_TYPES.REVIEW; } From a310260c4e61c55b4f150b7ef52afe0e6781161a Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 09:20:52 -0600 Subject: [PATCH 4/8] deprecate hasErrors --- src/libs/SearchUIUtils.ts | 2 +- src/types/onyx/SearchResults.ts | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 7f52f9dc0126..44ffe58578ae 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -264,7 +264,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr // We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (transaction?.errors || transaction?.hasErrors || report?.errors || report?.hasErrors) { + if (transaction?.errors || report?.errors) { return CONST.SEARCH.ACTION_TYPES.REVIEW; } diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index a0da40411724..513089ca60a8 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -159,9 +159,6 @@ type SearchReport = { /** Whether the report has violations or errors */ errors?: OnyxCommon.Errors; - /** Whether the transaction has violations or errors */ - hasErrors?: boolean; - /** Collection of report participants, indexed by their accountID */ participants?: Participants; }; @@ -370,9 +367,6 @@ type SearchTransaction = { /** Whether the action is loading */ isActionLoading?: boolean; - /** Whether the transaction has violations or errors */ - hasErrors?: boolean; - /** Whether the transaction has violations or errors */ errors?: OnyxCommon.Errors; }; From 646c4171a0b0623f70b268ed5a45956fb29c27d6 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 10:33:29 -0600 Subject: [PATCH 5/8] fix lint --- src/components/SelectionList/Search/ReportListItem.tsx | 2 -- src/components/SelectionList/Search/TransactionListItem.tsx | 2 -- src/libs/SearchUIUtils.ts | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 73d0ec8f8c10..6963675ef5c7 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -153,8 +153,6 @@ function ReportListItem({ canSelectMultiple={canSelectMultiple} onSelectRow={onSelectRow} onLongPressRow={onLongPressRow} - onDismissError={onDismissError} - errors={item.errors} pendingAction={item.pendingAction} keyForList={item.keyForList} onFocus={onFocus} diff --git a/src/components/SelectionList/Search/TransactionListItem.tsx b/src/components/SelectionList/Search/TransactionListItem.tsx index 42bf05179bdb..117ed37aaf7f 100644 --- a/src/components/SelectionList/Search/TransactionListItem.tsx +++ b/src/components/SelectionList/Search/TransactionListItem.tsx @@ -65,8 +65,6 @@ function TransactionListItem({ showTooltip={showTooltip} canSelectMultiple={canSelectMultiple} onSelectRow={onSelectRow} - onDismissError={onDismissError} - errors={item.errors} pendingAction={item.pendingAction} keyForList={item.keyForList} onFocus={onFocus} diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 44ffe58578ae..eb12b44c730a 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -374,7 +374,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx ...reportItem, action: getAction(data, key), keyForList: reportItem.reportID, - from: data.personalDetailsList?.[reportItem.accountID ?? -1], + from: data.personalDetailsList?.[reportItem.accountID ?? CONST.DEFAULT_NUMBER_ID], to: reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails, transactions, reportName: isIOUReport ? getIOUReportName(data, reportItem) : reportItem.reportName, From fbcffeb2d9456f813874e9ed29568211e1f71868 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 19 Dec 2024 10:41:28 -0600 Subject: [PATCH 6/8] fix eslint --- src/components/SelectionList/Search/ReportListItem.tsx | 2 -- src/components/SelectionList/Search/TransactionListItem.tsx | 1 - 2 files changed, 3 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 6963675ef5c7..594b6026fc5f 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -61,7 +61,6 @@ function ReportListItem({ canSelectMultiple, onCheckboxPress, onSelectRow, - onDismissError, onFocus, onLongPressRow, shouldSyncFocus, @@ -132,7 +131,6 @@ function ReportListItem({ canSelectMultiple={canSelectMultiple} onCheckboxPress={() => onCheckboxPress?.(transactionItem as unknown as TItem)} onSelectRow={onSelectRow} - onDismissError={onDismissError} onFocus={onFocus} onLongPressRow={onLongPressRow} shouldSyncFocus={shouldSyncFocus} diff --git a/src/components/SelectionList/Search/TransactionListItem.tsx b/src/components/SelectionList/Search/TransactionListItem.tsx index 117ed37aaf7f..2582f1fb23cc 100644 --- a/src/components/SelectionList/Search/TransactionListItem.tsx +++ b/src/components/SelectionList/Search/TransactionListItem.tsx @@ -18,7 +18,6 @@ function TransactionListItem({ canSelectMultiple, onSelectRow, onCheckboxPress, - onDismissError, onFocus, onLongPressRow, shouldSyncFocus, From 938f9366e23bdb27bcaae7fe0e4698f5c428e7fc Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 31 Dec 2024 08:51:53 -0700 Subject: [PATCH 7/8] optimistically clean up errors --- src/libs/actions/IOU.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 2658f8925e5c..8af13e8ceb0c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6986,6 +6986,7 @@ function getPayMoneyRequestParams( reimbursed: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, partial: full ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, + errors: null, }, }, { @@ -7009,6 +7010,7 @@ function getPayMoneyRequestParams( reimbursed: null, partial: null, }, + errors: null, }, }); From 6023f99292d73ee3f5dd1bb15c4bf95e26fcf3d7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 31 Dec 2024 09:31:39 -0700 Subject: [PATCH 8/8] fix ts --- src/libs/DebugUtils.ts | 3 +++ src/types/onyx/Report.ts | 3 +++ src/types/utils/whitelistedReportKeys.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index fd8ad40d7501..03287923feec 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -520,6 +520,8 @@ function validateReportDraftProperty(key: keyof Report, value: string) { ); case 'errorFields': return validateObject>(value, {}, 'string'); + case 'errors': + return validateObject>(value, {}); case 'privateNotes': return validateObject>( value, @@ -624,6 +626,7 @@ function validateReportDraftProperty(key: keyof Report, value: string) { reimbursed: CONST.RED_BRICK_ROAD_PENDING_ACTION, preview: CONST.RED_BRICK_ROAD_PENDING_ACTION, welcomeMessage: CONST.RED_BRICK_ROAD_PENDING_ACTION, + errors: CONST.RED_BRICK_ROAD_PENDING_ACTION, }); } } diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index ca15806c0aca..1ce9a76306e9 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -184,6 +184,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** Collection of errors that exist in report fields */ errorFields?: OnyxCommon.ErrorFields; + /** Errors used by Search to show RBR */ + errors?: OnyxCommon.Errors; + /** Whether the report is waiting on a bank account */ isWaitingOnBankAccount?: boolean; diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index ca7626565550..8fa8aab7adc1 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -47,6 +47,7 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< unheldNonReimbursableTotal: unknown; currency: unknown; errorFields: unknown; + errors: unknown; isWaitingOnBankAccount: unknown; isCancelledIOU: unknown; iouReportID: unknown;