From 979dc0d93db61ae9f9e2be77196778d8dc4df3d9 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 16 May 2026 20:44:22 +0530 Subject: [PATCH 1/4] Refactor `cleanUpMoneyRequest` to pass transactionThreadReport --- .../ReportActionItem/MoneyRequestReceiptView.tsx | 3 +++ src/components/Search/SearchList/ListItem/ChatListItem.tsx | 2 ++ src/libs/actions/IOU/DeleteMoneyRequest.ts | 4 +--- .../Debug/ReportAction/DebugReportActionCreatePage.tsx | 7 ++++++- src/pages/Debug/ReportAction/DebugReportActionPreview.tsx | 3 ++- .../TransactionDuplicate/DuplicateTransactionItem.tsx | 2 ++ src/pages/inbox/report/PureReportActionItem.tsx | 6 +++--- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 1a12d8b2f0cc..daf6ec34ba8b 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -140,6 +140,8 @@ function MoneyRequestReceiptView({ const [isLoading, setIsLoading] = useState(true); const parentReportAction = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined; + const [parentReportActionChildReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportAction?.childReportID)}`); + const originalReportID = useOriginalReportID(report?.reportID, parentReportAction); const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction); const isTrackExpense = !mergeTransactionID && isTrackExpenseReportNew(report, parentReport, parentReportAction); @@ -403,6 +405,7 @@ function MoneyRequestReceiptView({ transaction?.transactionID ?? linkedTransactionID, parentReportAction, report.reportID, + parentReportActionChildReport, iouReport, chatIOUReport, isChatIOUReportArchived, diff --git a/src/components/Search/SearchList/ListItem/ChatListItem.tsx b/src/components/Search/SearchList/ListItem/ChatListItem.tsx index e0413ccfd04a..b48953588284 100644 --- a/src/components/Search/SearchList/ListItem/ChatListItem.tsx +++ b/src/components/Search/SearchList/ListItem/ChatListItem.tsx @@ -29,6 +29,7 @@ function ChatListItem({ }: ChatListItemProps) { const reportActionItem = item as unknown as ReportActionListItemType; const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionItem?.reportID}`); + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionItem?.childReportID}`); const personalDetails = usePersonalDetails(); const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID); const styles = useThemeStyles(); @@ -76,6 +77,7 @@ function ChatListItem({ > onSelectRow(item)} parentReportAction={undefined} diff --git a/src/libs/actions/IOU/DeleteMoneyRequest.ts b/src/libs/actions/IOU/DeleteMoneyRequest.ts index 8c8ec568fa64..18c84f26d610 100644 --- a/src/libs/actions/IOU/DeleteMoneyRequest.ts +++ b/src/libs/actions/IOU/DeleteMoneyRequest.ts @@ -292,15 +292,13 @@ function cleanUpMoneyRequest( transactionID: string, reportAction: OnyxTypes.ReportAction, reportID: string, + transactionThreadReport: OnyxEntry, iouReport: OnyxEntry, chatReport: OnyxEntry, isChatIOUReportArchived: boolean | undefined, originalReportID: string | undefined, isSingleTransactionView = false, ) { - const allReports = getAllReports(); - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`]; - const {shouldDeleteTransactionThread, shouldDeleteIOUReport, updatedReportAction, updatedIOUReport, updatedReportPreviewAction, transactionThreadID, reportPreviewAction} = prepareToCleanUpMoneyRequest(transactionID, reportAction, transactionThreadReport, iouReport, chatReport, isChatIOUReportArchived, false); diff --git a/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx b/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx index cc68738eef12..0786f840a971 100644 --- a/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx +++ b/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useState} from 'react'; +import React, {useCallback, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import Button from '@components/Button'; @@ -53,6 +53,10 @@ function DebugReportActionCreatePage({ const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed; + const reportAction = useMemo(() => JSON.parse(draftReportAction.replaceAll('\n', '')) as ReportAction, [draftReportAction]); + + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`); + const [error, setError] = useState(); const createReportAction = useCallback(() => { @@ -111,6 +115,7 @@ function DebugReportActionCreatePage({ {!error ? ( ; /** The transaction thread report associated with the report for this action, if any */ - transactionThreadReport?: OnyxEntry; + transactionThreadReport: OnyxEntry; /** Report action belonging to the report's parent */ parentReportAction: OnyxEntry; @@ -327,7 +327,7 @@ function PureReportActionItem({ const dismissError = useCallback(() => { const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined; if (isSendingMoney && transactionID && reportID) { - cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, originalReportID, true); + cleanUpMoneyRequest(transactionID, action, reportID, transactionThreadReport, report, chatReport, undefined, originalReportID, true); return; } if (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && isReportActionLinked) { @@ -337,7 +337,7 @@ function PureReportActionItem({ clearError(transactionID); } clearAllRelatedReportActionErrors(reportID, action, originalReportID); - }, [action, isSendingMoney, reportID, originalReportID, isReportActionLinked, report, chatReport, navigation]); + }, [action, isSendingMoney, reportID, isReportActionLinked, originalReportID, transactionThreadReport, report, chatReport, navigation]); const showDismissReceiptErrorModal = useCallback(async () => { const result = await showConfirmModal({ From 8dda9b0998e826c8475e44adcf983d7bbe4bdfb8 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 20 May 2026 23:19:52 +0530 Subject: [PATCH 2/4] Fix tests --- tests/ui/ClearReportActionErrorsUITest.tsx | 1 + tests/ui/PureReportActionItemTest.tsx | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/ui/ClearReportActionErrorsUITest.tsx b/tests/ui/ClearReportActionErrorsUITest.tsx index e46b322e68db..2e0e5407ff51 100644 --- a/tests/ui/ClearReportActionErrorsUITest.tsx +++ b/tests/ui/ClearReportActionErrorsUITest.tsx @@ -93,6 +93,7 @@ describe('ClearReportActionErrors UI', () => { { { { { { { { { { { { { { { { { parentReportActionID: 'parentAction', ownerAccountID: 0, }} + transactionThreadReport={undefined} parentReportAction={undefined} action={action} displayAsGroup={false} @@ -1548,6 +1564,7 @@ describe('PureReportActionItem', () => { { { { { { { { { { { Date: Sat, 23 May 2026 16:13:57 +0530 Subject: [PATCH 3/4] fix type casting --- .../DebugReportActionCreatePage.tsx | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx b/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx index 0786f840a971..2ea3419e86dc 100644 --- a/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx +++ b/src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx @@ -28,6 +28,19 @@ import type {PersonalDetailsList, ReportAction, Session} from '@src/types/onyx'; type DebugReportActionCreatePageProps = PlatformStackScreenProps; +function isParsedReportAction(value: unknown): value is ReportAction { + return typeof value === 'object' && value !== null && 'reportActionID' in value; +} + +function parseReportActionJSON(draftReportAction: string): ReportAction | null { + try { + const parsedReportAction: unknown = JSON.parse(draftReportAction.replaceAll('\n', '')); + return isParsedReportAction(parsedReportAction) ? parsedReportAction : null; + } catch { + return null; + } +} + const getInitialReportAction = (reportID: string, session: OnyxEntry, personalDetailsList: OnyxEntry) => DebugUtils.stringifyJSON({ actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, @@ -53,19 +66,21 @@ function DebugReportActionCreatePage({ const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed; - const reportAction = useMemo(() => JSON.parse(draftReportAction.replaceAll('\n', '')) as ReportAction, [draftReportAction]); + const reportAction = useMemo(() => parseReportActionJSON(draftReportAction), [draftReportAction]); const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`); const [error, setError] = useState(); const createReportAction = useCallback(() => { - const parsedReportAction = JSON.parse(draftReportAction.replaceAll('\n', '')) as ReportAction; + if (!reportAction) { + return; + } Debug.mergeDebugData(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { - [parsedReportAction.reportActionID]: parsedReportAction, + [reportAction.reportActionID]: reportAction, }); Navigation.navigate(ROUTES.DEBUG_REPORT_TAB_ACTIONS.getRoute(reportID)); - }, [draftReportAction, reportID]); + }, [reportAction, reportID]); const editJSON = useCallback( (updatedJSON: string) => { @@ -112,9 +127,9 @@ function DebugReportActionCreatePage({ {translate('debug.preview')} - {!error ? ( + {!error && reportAction ? ( Date: Sun, 24 May 2026 19:57:58 +0530 Subject: [PATCH 4/4] fixes --- tests/ui/PureReportActionItemTest.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/PureReportActionItemTest.tsx b/tests/ui/PureReportActionItemTest.tsx index a86558fec1df..0903b1c58461 100644 --- a/tests/ui/PureReportActionItemTest.tsx +++ b/tests/ui/PureReportActionItemTest.tsx @@ -2638,6 +2638,7 @@ describe('PureReportActionItem', () => {