diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 96a6912f1c54..ef9edc6e7830 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -53,6 +53,7 @@ import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import useOriginalReportID from '@hooks/useOriginalReportID'; import useCardFeedErrors from '@hooks/useCardFeedErrors'; import {getBrokenConnectionUrlToFixPersonalCard} from '@libs/CardUtils'; import ReportActionItemImage from './ReportActionItemImage'; @@ -117,6 +118,7 @@ function MoneyRequestReceiptView({ const [isLoading, setIsLoading] = useState(true); const parentReportAction = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined; + const originalReportID = useOriginalReportID(report?.reportID, parentReportAction); const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction); const isTrackExpense = !mergeTransactionID && isTrackExpenseReportNew(report, parentReport, parentReportAction); const moneyRequestReport = parentReport; @@ -279,16 +281,26 @@ function MoneyRequestReceiptView({ return; } if (parentReportAction) { - cleanUpMoneyRequest(transaction?.transactionID ?? linkedTransactionID, parentReportAction, report.reportID, iouReport, chatIOUReport, isChatIOUReportArchived, true); + cleanUpMoneyRequest( + transaction?.transactionID ?? linkedTransactionID, + parentReportAction, + report.reportID, + iouReport, + chatIOUReport, + isChatIOUReportArchived, + originalReportID, + true, + ); return; } } + if (!transaction?.transactionID) { if (!linkedTransactionID) { return; } clearError(linkedTransactionID); - clearAllRelatedReportActionErrors(report.reportID, parentReportAction); + clearAllRelatedReportActionErrors(report.reportID, parentReportAction, originalReportID); return; } if (!isEmptyObject(transactionAndReportActionErrors)) { @@ -296,7 +308,7 @@ function MoneyRequestReceiptView({ } if (!isEmptyObject(errorsWithoutReportCreation)) { clearError(transaction.transactionID); - clearAllRelatedReportActionErrors(report.reportID, parentReportAction); + clearAllRelatedReportActionErrors(report.reportID, parentReportAction, originalReportID); } if (!isEmptyObject(reportCreationError)) { if (isInNarrowPaneModal) { diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 73fe14fdb63b..ddf12cbe4838 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -8842,6 +8842,7 @@ function cleanUpMoneyRequest( iouReport: OnyxEntry, chatReport: OnyxEntry, isChatIOUReportArchived: boolean | undefined, + originalReportID: string | undefined, isSingleTransactionView = false, ) { const {shouldDeleteTransactionThread, shouldDeleteIOUReport, updatedReportAction, updatedIOUReport, updatedReportPreviewAction, transactionThreadID, reportPreviewAction} = @@ -8999,7 +9000,7 @@ function cleanUpMoneyRequest( } if (!shouldDeleteIOUReport) { - clearAllRelatedReportActionErrors(reportID, reportAction); + clearAllRelatedReportActionErrors(reportID, reportAction, originalReportID); } // First, update the reportActions to ensure related actions are not displayed. @@ -9008,7 +9009,7 @@ function cleanUpMoneyRequest( // eslint-disable-next-line @typescript-eslint/no-deprecated InteractionManager.runAfterInteractions(() => { if (shouldDeleteIOUReport) { - clearAllRelatedReportActionErrors(reportID, reportAction); + clearAllRelatedReportActionErrors(reportID, reportAction, originalReportID); } // After navigation, update the remaining data. Onyx.update(onyxUpdates); diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 739e87d7625c..39529ea60884 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -26,9 +26,7 @@ Onyx.connect({ }, }); -function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) { - const originalReportID = getOriginalReportID(reportID, reportAction, undefined); - +function clearReportActionErrors(reportID: string, reportAction: ReportAction, originalReportID: string | undefined, keys?: string[]) { if (!reportAction?.reportActionID) { return; } @@ -80,27 +78,36 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction, k ignore: `undefined` means we want to check both parent and children report actions ignore: `parent` or `child` means we want to ignore checking parent or child report actions because they've been previously checked */ -function clearAllRelatedReportActionErrors(reportID: string | undefined, reportAction: ReportAction | null | undefined, ignore?: IgnoreDirection, keys?: string[]) { +function clearAllRelatedReportActionErrors( + reportID: string | undefined, + reportAction: ReportAction | null | undefined, + originalReportID: string | undefined, + ignore?: IgnoreDirection, + keys?: string[], +) { const errorKeys = keys ?? Object.keys(reportAction?.errors ?? {}); if (!reportAction || errorKeys.length === 0 || !reportID) { return; } - clearReportActionErrors(reportID, reportAction, keys); + clearReportActionErrors(reportID, reportAction, originalReportID, keys); const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; if (report?.parentReportID && report?.parentReportActionID && ignore !== 'parent') { const parentReportAction = getReportAction(report.parentReportID, report.parentReportActionID); const parentErrorKeys = Object.keys(parentReportAction?.errors ?? {}).filter((err) => errorKeys.includes(err)); + const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`] ?? {}; + const parentOriginalReportID = getOriginalReportID(report.parentReportID, parentReportAction, parentReportActions); - clearAllRelatedReportActionErrors(report.parentReportID, parentReportAction, 'child', parentErrorKeys); + clearAllRelatedReportActionErrors(report.parentReportID, parentReportAction, parentOriginalReportID, 'child', parentErrorKeys); } if (reportAction.childReportID && ignore !== 'child') { const childActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.childReportID}`] ?? {}; for (const action of Object.values(childActions)) { const childErrorKeys = Object.keys(action.errors ?? {}).filter((err) => errorKeys.includes(err)); - clearAllRelatedReportActionErrors(reportAction.childReportID, action, 'parent', childErrorKeys); + const childOriginalReportID = getOriginalReportID(reportAction.childReportID, action, childActions); + clearAllRelatedReportActionErrors(reportAction.childReportID, action, childOriginalReportID, 'parent', childErrorKeys); } } } diff --git a/src/pages/inbox/report/PureReportActionItem.tsx b/src/pages/inbox/report/PureReportActionItem.tsx index 260bb9ece480..af721e9c7501 100644 --- a/src/pages/inbox/report/PureReportActionItem.tsx +++ b/src/pages/inbox/report/PureReportActionItem.tsx @@ -442,7 +442,13 @@ type PureReportActionItemProps = { clearError?: (transactionID: string) => void; /** Function to clear all errors from a report action */ - clearAllRelatedReportActionErrors?: (reportID: string | undefined, reportAction: OnyxTypes.ReportAction | null | undefined, ignore?: IgnoreDirection, keys?: string[]) => void; + clearAllRelatedReportActionErrors?: ( + reportID: string | undefined, + reportAction: OnyxTypes.ReportAction | null | undefined, + originalReportID: string | undefined, + ignore?: IgnoreDirection, + keys?: string[], + ) => void; /** Function to dismiss the actionable whisper for tracking expenses */ dismissTrackExpenseActionableWhisper?: (reportID: string | undefined, reportAction: OnyxEntry) => void; @@ -621,14 +627,14 @@ function PureReportActionItem({ const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined; if (isSendingMoney && transactionID && reportID) { const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, true); + cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, originalReportID, true); return; } if (transactionID) { clearError(transactionID); } - clearAllRelatedReportActionErrors(reportID, action); - }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError]); + clearAllRelatedReportActionErrors(reportID, action, originalReportID); + }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError, originalReportID]); const showDismissReceiptErrorModal = useCallback(async () => { const result = await showConfirmModal({ diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 0a3565e65554..080217e17906 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -2552,7 +2552,7 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { if (iouReportID) { - clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null); + clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null, iouReportID); } resolve(); }),