diff --git a/src/CONST.ts b/src/CONST.ts index 4d7049271e78..f1d8374509e2 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1043,6 +1043,7 @@ const CONST = { EMPTY_ARRAY, EMPTY_OBJECT, DEFAULT_NUMBER_ID, + FAKE_REPORT_ID: 'FAKE_REPORT_ID', USE_EXPENSIFY_URL, EXPENSIFY_URL, GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com', diff --git a/src/ROUTES.ts b/src/ROUTES.ts index df9274149051..124c6fae594c 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -83,12 +83,14 @@ const ROUTES = { backTo, moneyRequestReportActionID, transactionID, + iouReportID, }: { reportID: string | undefined; reportActionID?: string; backTo?: string; moneyRequestReportActionID?: string; transactionID?: string; + iouReportID?: string; }) => { if (!reportID) { Log.warn('Invalid reportID is used to build the SEARCH_REPORT route'); @@ -105,6 +107,10 @@ const ROUTES = { queryParams.push(`moneyRequestReportActionID=${moneyRequestReportActionID}`); } + if (iouReportID) { + queryParams.push(`iouReportID=${iouReportID}`); + } + const queryString = queryParams.length > 0 ? (`${baseRoute}?${queryParams.join('&')}` as const) : baseRoute; return getUrlWithBackToParam(queryString, backTo); }, @@ -376,10 +382,19 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string, backTo?: string) => { + getRoute: ( + reportID: string | undefined, + reportActionID?: string, + referrer?: string, + moneyRequestReportActionID?: string, + transactionID?: string, + backTo?: string, + iouReportID?: string, + ) => { if (!reportID) { Log.warn('Invalid reportID is used to build the REPORT_WITH_ID route'); } + const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const); const queryParams: string[] = []; @@ -393,6 +408,10 @@ const ROUTES = { queryParams.push(`transactionID=${transactionID}`); } + if (iouReportID) { + queryParams.push(`iouReportID=${iouReportID}`); + } + const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; return getUrlWithBackToParam(`${baseRoute}${queryString}` as const, backTo); @@ -574,10 +593,15 @@ const ROUTES = { }, MONEY_REQUEST_HOLD_REASON: { route: ':type/edit/reason/:transactionID?/:searchHash?', - getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string, searchHash?: number) => { - const route = searchHash - ? (`${type as string}/edit/reason/${transactionID}/${searchHash}/?backTo=${backTo}&reportID=${reportID}` as const) - : (`${type as string}/edit/reason/${transactionID}/?backTo=${backTo}&reportID=${reportID}` as const); + getRoute: (type: ValueOf, transactionID: string, reportID: string | undefined, backTo: string, searchHash?: number) => { + let route = searchHash + ? (`${type as string}/edit/reason/${transactionID}/${searchHash}/?backTo=${backTo}` as const) + : (`${type as string}/edit/reason/${transactionID}/?backTo=${backTo}` as const); + + if (reportID) { + route = `${route}&reportID=${reportID}` as const; + } + return route; }, }, diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 6cf5247b8501..3051754ff187 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -16,16 +16,18 @@ import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsAction import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; -import {downloadReportPDF, exportReportToCSV, exportReportToPDF, exportToIntegration, markAsManuallyExported, openUnreportedExpense} from '@libs/actions/Report'; +import {downloadReportPDF, exportReportToCSV, exportReportToPDF, exportToIntegration, markAsManuallyExported, openReport, openUnreportedExpense} from '@libs/actions/Report'; import {getThreadReportIDsForTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils'; import Navigation from '@libs/Navigation/Navigation'; import {buildOptimisticNextStepForPreventSelfApprovalsEnabled} from '@libs/NextStepUtils'; import {getValidConnectedIntegration} from '@libs/PolicyUtils'; -import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; +import {getIOUActionForReportID, getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import {getReportPrimaryAction} from '@libs/ReportPrimaryActionUtils'; import {getSecondaryReportActions} from '@libs/ReportSecondaryActionUtils'; import { + buildTransactionThread, changeMoneyRequestHoldStatus, + generateReportID, getArchiveReason, getBankAccountRoute, getIntegrationIcon, @@ -547,9 +549,14 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea success text={translate('iou.reviewDuplicates')} onPress={() => { - const threadID = transactionThreadReportID ?? getFirstDuplicateThreadID(transactions, reportActions); + let threadID = transactionThreadReportID ?? getFirstDuplicateThreadID(transactions, reportActions); if (!threadID) { - return; + threadID = generateReportID(); + const duplicateTransaction = transactions.find((reportTransaction) => isDuplicate(reportTransaction.transactionID)); + const transactionID = duplicateTransaction?.transactionID; + const iouAction = getIOUActionForReportID(moneyRequestReport?.reportID, transactionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, moneyRequestReport, undefined, threadID); + openReport(threadID, undefined, session?.email ? [session?.email] : [], optimisticTransactionThread, iouAction?.reportActionID); } Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(threadID)); }} diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx index 9bf9b1886cb0..869f1fc2d248 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx @@ -27,14 +27,17 @@ import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils'; import {navigationRef} from '@libs/Navigation/Navigation'; import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils'; -import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils'; +import {generateReportID, getMoneyRequestSpendBreakdown} from '@libs/ReportUtils'; import {compareValues} from '@libs/SearchUIUtils'; import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear'; import Navigation from '@navigation/Navigation'; +import type {ReportsSplitNavigatorParamList} from '@navigation/types'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; +import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; +import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import {useMoneyRequestReportContext} from './MoneyRequestReportContext'; import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader'; @@ -74,6 +77,8 @@ type SortedTransactions = { sortOrder: SortOrder; }; +type ReportScreenNavigationProps = ReportsSplitNavigatorParamList[typeof SCREENS.REPORT]; + const isSortableColumnName = (key: unknown): key is SortableColumnName => !!sortableColumnNames.find((val) => val === key); const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => { @@ -151,19 +156,27 @@ function MoneyRequestReportTransactionList({report, transactions, reportActions, const navigateToTransaction = useCallback( (activeTransaction: OnyxTypes.Transaction) => { const iouAction = getIOUActionForTransactionID(reportActions, activeTransaction.transactionID); - const reportIDToNavigate = iouAction?.childReportID; - if (!reportIDToNavigate) { - return; - } + const reportIDToNavigate = iouAction?.childReportID ?? generateReportID(); - const backTo = Navigation.getActiveRoute(); + const backTo = Navigation.getActiveRoute() as Route; // Single transaction report will open in RHP, and we need to find every other report ID for the rest of transactions // to display prev/next arrows in RHP for navigating between transactions const sortedSiblingTransactionReportIDs = getThreadReportIDsForTransactions(reportActions, sortedTransactions); setActiveTransactionThreadIDs(sortedSiblingTransactionReportIDs); - Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: reportIDToNavigate, backTo})); + const routeParams = { + reportID: reportIDToNavigate, + backTo, + } as ReportScreenNavigationProps; + + if (!iouAction?.childReportID) { + routeParams.moneyRequestReportActionID = iouAction?.reportActionID; + routeParams.transactionID = activeTransaction.transactionID; + routeParams.iouReportID = activeTransaction.reportID; + } + + Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(routeParams)); }, [reportActions, sortedTransactions], ); diff --git a/src/components/ReportActionItem/MoneyRequestAction.tsx b/src/components/ReportActionItem/MoneyRequestAction.tsx index 6850a53b73e0..3f106138485c 100644 --- a/src/components/ReportActionItem/MoneyRequestAction.tsx +++ b/src/components/ReportActionItem/MoneyRequestAction.tsx @@ -98,7 +98,7 @@ function MoneyRequestAction({ const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : CONST.DEFAULT_NUMBER_ID; if (!action?.childReportID && transactionID && action.reportActionID) { const optimisticReportID = generateReportID(); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID, Navigation.getActiveRoute())); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID, Navigation.getActiveRoute(), requestReportID)); return; } diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index d7a55c9e2e5d..2cfb21150cef 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -22,6 +22,7 @@ import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import Log from '@libs/Log'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; +import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import {generateReportID} from '@libs/ReportUtils'; import {buildSearchQueryString} from '@libs/SearchQueryUtils'; import { @@ -379,8 +380,28 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; const isTransactionItem = isTransactionListItemType(item); + const backTo = Navigation.getActiveRoute(); + + // If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user + if (isTransactionItem && item.transactionThreadReportID === CONST.REPORT.UNREPORTED_REPORT_ID) { + const transactionThreadReportID = generateReportID(); + const reportAction = getReportAction(item.reportID, item.moneyRequestReportActionID); + const iouReportID = isMoneyRequestAction(reportAction) ? getOriginalMessage(reportAction)?.IOUReportID : undefined; + + updateSearchResultsWithTransactionThreadReportID(hash, item.transactionID, transactionThreadReportID); + Navigation.navigate( + ROUTES.SEARCH_REPORT.getRoute({ + reportID: transactionThreadReportID, + backTo, + moneyRequestReportActionID: item.moneyRequestReportActionID, + transactionID: item.transactionID, + iouReportID, + }), + ); + return; + } - let reportID = + const reportID = isTransactionItem && (!item.isFromOneTransactionReport || isFromSelfDM) && item.transactionThreadReportID !== CONST.REPORT.UNREPORTED_REPORT_ID ? item.transactionThreadReportID : item.reportID; @@ -389,7 +410,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return; } - const backTo = Navigation.getActiveRoute(); const shouldHandleTransactionAsReport = isReportListItemType(item) || (isTransactionItem && isOpenedAsReport); if (canUseTableReportView && shouldHandleTransactionAsReport) { @@ -397,21 +417,6 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return; } - // If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user - if (isTransactionItem && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) { - reportID = generateReportID(); - updateSearchResultsWithTransactionThreadReportID(hash, item.transactionID, reportID); - Navigation.navigate( - ROUTES.SEARCH_REPORT.getRoute({ - reportID, - backTo, - moneyRequestReportActionID: item.moneyRequestReportActionID, - transactionID: item.transactionID, - }), - ); - return; - } - if (isReportActionListItemType(item)) { const reportActionID = item.reportActionID; Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, reportActionID, backTo})); diff --git a/src/libs/API/parameters/CreatePerDiemRequestParams.ts b/src/libs/API/parameters/CreatePerDiemRequestParams.ts index 480acd9ca23d..24f13f203adb 100644 --- a/src/libs/API/parameters/CreatePerDiemRequestParams.ts +++ b/src/libs/API/parameters/CreatePerDiemRequestParams.ts @@ -17,7 +17,7 @@ type CreatePerDiemRequestParams = { createdChatReportActionID?: string; createdIOUReportActionID?: string; reportPreviewReportActionID: string; - transactionThreadReportID: string; + transactionThreadReportID?: string; createdReportActionIDForThread: string | undefined; billable?: boolean; attendees?: string; diff --git a/src/libs/API/parameters/HoldMoneyRequestParams.ts b/src/libs/API/parameters/HoldMoneyRequestParams.ts index 357194d7ae56..b22e421898d1 100644 --- a/src/libs/API/parameters/HoldMoneyRequestParams.ts +++ b/src/libs/API/parameters/HoldMoneyRequestParams.ts @@ -3,6 +3,8 @@ type HoldMoneyRequestParams = { comment: string; reportActionID: string; commentReportActionID: string; + transactionThreadReportID?: string; + createdReportActionIDForThread?: string; }; export default HoldMoneyRequestParams; diff --git a/src/libs/API/parameters/MergeDuplicatesParams.ts b/src/libs/API/parameters/MergeDuplicatesParams.ts index b5ef56a52502..e1cdfd0903c6 100644 --- a/src/libs/API/parameters/MergeDuplicatesParams.ts +++ b/src/libs/API/parameters/MergeDuplicatesParams.ts @@ -13,6 +13,8 @@ type MergeDuplicatesParams = { receiptID: number; reportID: string | undefined; reportActionID?: string | undefined; + transactionThreadReportID?: string; + createdReportActionIDForThread?: string; }; export default MergeDuplicatesParams; diff --git a/src/libs/API/parameters/RequestMoneyParams.ts b/src/libs/API/parameters/RequestMoneyParams.ts index 74a435600cd2..029df6eae5b7 100644 --- a/src/libs/API/parameters/RequestMoneyParams.ts +++ b/src/libs/API/parameters/RequestMoneyParams.ts @@ -25,8 +25,8 @@ type RequestMoneyParams = { taxAmount: number; billable?: boolean; receiptGpsPoints?: string; - transactionThreadReportID: string; - createdReportActionIDForThread: string | undefined; + transactionThreadReportID?: string; + createdReportActionIDForThread?: string | undefined; reimbursible?: boolean; description?: string; attendees?: string; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index fc5eda8a7f94..a91c04373b96 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1650,6 +1650,7 @@ type ReportsSplitNavigatorParamList = { backTo?: Routes; moneyRequestReportActionID?: string; transactionID?: string; + iouReportID?: string; }; }; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 934709be68c7..35b756cdefeb 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1249,7 +1249,6 @@ function getOneTransactionThreadReportID( if ( actionType && iouRequestTypesSet.has(actionType) && - action.childReportID && // Include deleted IOU reportActions if: // - they have an associated IOU transaction ID or // - they have visible childActions (like comments) that we'd want to display @@ -1277,8 +1276,8 @@ function getOneTransactionThreadReportID( return; } - // Ensure we have a childReportID associated with the IOU report action - return singleAction?.childReportID; + // Since we don't always create transaction thread optimistically, we return CONST.FAKE_REPORT_ID + return singleAction?.childReportID ?? CONST.FAKE_REPORT_ID; } /** diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 11882161be61..a5808fa7d40a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -609,7 +609,7 @@ type OptimisticModifiedExpenseReportAction = Pick< | 'delegateAccountID' > & {reportID?: string}; -type OptimisticMoneyRequestEntities = { +type BaseOptimisticMoneyRequestEntities = { iouReport: Report; type: ValueOf; amount: number; @@ -627,6 +627,10 @@ type OptimisticMoneyRequestEntities = { linkedTrackedExpenseReportAction?: ReportAction; }; +type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread?: boolean}; +type OptimisticMoneyRequestEntitiesWithTransactionThreadFlag = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread: boolean}; +type OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag = BaseOptimisticMoneyRequestEntities; + type OptimisticTaskReport = SetRequired< Pick< Report, @@ -3993,8 +3997,8 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, sea const transactionID = getOriginalMessage(reportAction)?.IOUTransactionID; - if (!transactionID || !reportAction.childReportID) { - Log.warn('Missing transactionID and reportAction.childReportID during the change of the money request hold status'); + if (!transactionID) { + Log.warn('Missing transactionID during the change of the money request hold status'); return; } @@ -4002,7 +4006,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, sea const isOnHold = isOnHoldTransactionUtils(transaction); const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; - if (isOnHold) { + if (isOnHold && reportAction.childReportID) { unholdRequest(transactionID, reportAction.childReportID, searchHash); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRoute()); @@ -7349,6 +7353,7 @@ function buildTransactionThread( reportAction: OnyxEntry, moneyRequestReport: OnyxEntry, existingTransactionThreadReportID?: string, + optimisticTransactionThreadReportID?: string, ): OptimisticChatReport { const participantAccountIDs = [...new Set([currentUserAccountID, Number(reportAction?.actorAccountID)])].filter(Boolean) as number[]; const existingTransactionThreadReport = getReportOrDraftReport(existingTransactionThreadReportID); @@ -7371,6 +7376,7 @@ function buildTransactionThread( notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportActionID: reportAction?.reportActionID, parentReportID: moneyRequestReport?.reportID, + optimisticReportID: optimisticTransactionThreadReportID, }); } @@ -7383,6 +7389,12 @@ function buildTransactionThread( * 4. Transaction Thread linked to the IOU action via `parentReportActionID` * 5. CREATED action for the Transaction Thread */ +function buildOptimisticMoneyRequestEntities( + optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag, +): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null]; +function buildOptimisticMoneyRequestEntities( + optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithTransactionThreadFlag, +): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport | undefined, OptimisticCreatedReportAction | null]; function buildOptimisticMoneyRequestEntities({ iouReport, type, @@ -7396,10 +7408,17 @@ function buildOptimisticMoneyRequestEntities({ isSettlingUp = false, isSendMoneyFlow = false, isOwnPolicyExpenseChat = false, + shouldGenerateOptimisticTransactionThread = true, isPersonalTrackingExpense, existingTransactionThreadReportID, linkedTrackedExpenseReportAction, -}: OptimisticMoneyRequestEntities): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] { +}: OptimisticMoneyRequestEntities): [ + OptimisticCreatedReportAction, + OptimisticCreatedReportAction, + OptimisticIOUReportAction, + OptimisticChatReport | undefined, + OptimisticCreatedReportAction | null, +] { const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail); // The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat. @@ -7424,11 +7443,11 @@ function buildOptimisticMoneyRequestEntities({ }); // Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined - const transactionThread = buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID); - const createdActionForTransactionThread = existingTransactionThreadReportID ? null : buildOptimisticCreatedReportAction(payeeEmail); + const transactionThread = shouldGenerateOptimisticTransactionThread ? buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID) : undefined; + const createdActionForTransactionThread = !!existingTransactionThreadReportID || !shouldGenerateOptimisticTransactionThread ? null : buildOptimisticCreatedReportAction(payeeEmail); // The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together - iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread.reportID; + iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread?.reportID; return [createdActionForChat, createdActionForIOUReport, iouAction, transactionThread, createdActionForTransactionThread]; } @@ -9217,12 +9236,12 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ /** * Get optimistic data of parent report action - * @param reportID The reportID of the report that is updated + * @param reportOrID The reportID of the report that is updated or the optimistic report on its own * @param lastVisibleActionCreated Last visible action created of the child report * @param type The type of action in the child report */ -function getOptimisticDataForParentReportAction(reportID: string | undefined, lastVisibleActionCreated: string, type: string): Array { - const report = getReportOrDraftReport(reportID); +function getOptimisticDataForParentReportAction(reportOrID: Report | string | undefined, lastVisibleActionCreated: string, type: string): Array { + const report = typeof reportOrID === 'string' ? getReportOrDraftReport(reportOrID) : reportOrID; if (!report || isEmptyObject(report)) { return []; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 0fdb551ae682..039408dd3d94 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -16,6 +16,7 @@ import type { CreateWorkspaceParams, DeleteMoneyRequestParams, DetachReceiptParams, + HoldMoneyRequestParams, MergeDuplicatesParams, PayInvoiceParams, PayMoneyRequestParams, @@ -77,6 +78,7 @@ import { } from '@libs/PolicyUtils'; import { getAllReportActions, + getIOUActionForReportID, getIOUReportIDFromReportActionPreview, getLastVisibleAction, getLastVisibleMessage, @@ -115,8 +117,10 @@ import { buildOptimisticSubmittedReportAction, buildOptimisticUnapprovedReportAction, buildOptimisticUnHoldReportAction, + buildTransactionThread, canBeAutoReimbursed, canUserPerformWriteAction as canUserPerformWriteActionReportUtils, + generateReportID, getAllHeldTransactions as getAllHeldTransactionsReportUtils, getAllPolicyReports, getApprovalChain, @@ -247,7 +251,7 @@ type MoneyRequestInformation = { createdChatReportActionID?: string; createdIOUReportActionID?: string; reportPreviewAction: OnyxTypes.ReportAction; - transactionThreadReportID: string; + transactionThreadReportID?: string; createdReportActionIDForThread: string | undefined; onyxData: OnyxData; billable?: boolean; @@ -420,6 +424,7 @@ type MoneyRequestInformationParams = { existingTransactionID?: string; existingTransaction?: OnyxEntry; retryParams?: StartSplitBilActionParams | CreateTrackExpenseParams | RequestMoneyInformation | ReplaceReceipt; + shouldGenerateOptimisticTransactionThread?: boolean; }; type MoneyRequestOptimisticParams = { @@ -435,8 +440,8 @@ type MoneyRequestOptimisticParams = { }; transactionParams: { transaction: OnyxTypes.Transaction; - transactionThreadReport: OptimisticChatReport | null; - transactionThreadCreatedReportAction: OptimisticCreatedReportAction | null; + transactionThreadReport?: OptimisticChatReport | null; + transactionThreadCreatedReportAction?: OptimisticCreatedReportAction | null; }; policyRecentlyUsed: { categories?: string[]; @@ -3093,6 +3098,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma existingTransactionID, moneyRequestReportID = '', retryParams, + shouldGenerateOptimisticTransactionThread = true, } = moneyRequestInformation; const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams; const {policy, policyCategories, policyTagList} = policyParams; @@ -3212,6 +3218,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma paymentType: isSelectedManagerMcTest(participant.login) ? CONST.IOU.PAYMENT_TYPE.ELSEWHERE : undefined, existingTransactionThreadReportID: linkedTrackedExpenseReportAction?.childReportID, linkedTrackedExpenseReportAction, + shouldGenerateOptimisticTransactionThread, }); let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); @@ -4676,30 +4683,32 @@ const getConvertTrackedExpenseInformation = ( // Build modified expense report action with the transaction changes const modifiedExpenseReportAction = buildOptimisticMovedTransactionAction(transactionThreadReportID, moneyRequestReportID ?? CONST.REPORT.UNREPORTED_REPORT_ID); - optimisticData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: modifiedExpenseReportAction, - }, - }); - successData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: {pendingAction: null}, - }, - }); - failureData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: { - ...modifiedExpenseReportAction, - errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'), + if (transactionThreadReportID) { + optimisticData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: modifiedExpenseReportAction, }, - }, - }); + }); + successData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: {pendingAction: null}, + }, + }); + failureData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: { + ...modifiedExpenseReportAction, + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'), + }, + }, + }); + } return {optimisticData, successData, failureData, modifiedExpenseReportActionID: modifiedExpenseReportAction.reportActionID}; }; @@ -4748,7 +4757,7 @@ type ConvertTrackedExpenseToRequestParams = { merchant: string; created: string; attendees?: Attendee[]; - transactionThreadReportID: string; + transactionThreadReportID?: string; }; chatParams: { reportID: string; @@ -5051,29 +5060,18 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { }, }; - const { - payerAccountID, - payerEmail, - iouReport, - chatReport, - transaction, - iouAction, - createdChatReportActionID, - createdIOUReportActionID, - reportPreviewAction, - transactionThreadReportID, - createdReportActionIDForThread, - onyxData, - } = getMoneyRequestInformation({ - parentChatReport: isMovingTransactionFromTrackExpense ? undefined : currentChatReport, - participantParams, - policyParams, - transactionParams, - moneyRequestReportID, - existingTransactionID, - existingTransaction: isDistanceRequestTransactionUtils(existingTransaction) ? existingTransaction : undefined, - retryParams, - }); + const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = + getMoneyRequestInformation({ + parentChatReport: isMovingTransactionFromTrackExpense ? undefined : currentChatReport, + participantParams, + policyParams, + transactionParams, + moneyRequestReportID, + existingTransactionID, + existingTransaction: isDistanceRequestTransactionUtils(existingTransaction) ? existingTransaction : undefined, + retryParams, + shouldGenerateOptimisticTransactionThread: false, + }); const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport.reportID; switch (action) { @@ -5111,7 +5109,6 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { actionableWhisperReportActionID, linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID, - transactionThreadReportID, }, chatParams: { reportID: chatReport.reportID, @@ -5153,8 +5150,6 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { billable, // This needs to be a string of JSON because of limitations with the fetch() API and nested objects receiptGpsPoints: gpsPoints ? JSON.stringify(gpsPoints) : undefined, - transactionThreadReportID, - createdReportActionIDForThread, reimbursible, description: parsedComment, attendees: attendees ? JSON.stringify(attendees) : undefined, @@ -10213,17 +10208,29 @@ function adjustRemainingSplitShares(transaction: NonNullable notifyNewAction(currentReportID, userAccountID)); @@ -10573,7 +10633,9 @@ function getIOUActionForTransactions(transactionIDList: Array value?.email, canBeMissing: false}); + + const {reportActions: reportActionsWithDeletedExpenses} = usePaginatedReportActions(reportIDFromRoute); + const reportActions = reportActionsWithDeletedExpenses.filter((value) => !isDeletedParentAction(value)); + const transactionThreadReportID = getOneTransactionThreadReportID(reportIDFromRoute, reportActions ?? [], isOffline); + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute); @@ -58,9 +69,29 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) { const reportID = report?.reportID; + const fetchReport = useCallback(() => { + if (reportMetadata.isOptimisticReport) { + return; + } + + // If there is one transaction thread that has not yet been created, we should create it. + if (transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport && currentUserEmail) { + const optimisticTransactionThreadReportID = generateReportID(); + const transactions = getReportTransactions(reportID); + const oneTransactionID = transactions.at(0)?.transactionID; + const iouAction = getIOUActionForReportID(reportID, oneTransactionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, report, undefined, optimisticTransactionThreadReportID); + openReport(optimisticTransactionThreadReportID, undefined, [currentUserEmail], optimisticTransactionThread, iouAction?.reportActionID, false, [], undefined, true); + } + + openReport(reportID, undefined, [], undefined, undefined, false, [], undefined, true); + // We don't want to call openReport when report is changed + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + }, [reportMetadata.isOptimisticReport, currentUserEmail, reportID, transactionThreadReport, transactionThreadReportID]); + useEffect(() => { - openReport(reportIDFromRoute, '', [], undefined, undefined, false, [], undefined, true); - }, [reportIDFromRoute]); + fetchReport(); + }, [fetchReport]); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = useMemo( diff --git a/src/pages/TransactionDuplicate/Confirmation.tsx b/src/pages/TransactionDuplicate/Confirmation.tsx index 734d409380e9..8fb7a9f73308 100644 --- a/src/pages/TransactionDuplicate/Confirmation.tsx +++ b/src/pages/TransactionDuplicate/Confirmation.tsx @@ -25,6 +25,7 @@ import variables from '@styles/variables'; import * as IOU from '@src/libs/actions/IOU'; import * as ReportActionsUtils from '@src/libs/ReportActionsUtils'; import * as ReportUtils from '@src/libs/ReportUtils'; +import {generateReportID} from '@src/libs/ReportUtils'; import * as TransactionUtils from '@src/libs/TransactionUtils'; import {getTransactionID} from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -55,18 +56,18 @@ function Confirmation() { const isReportOwner = iouReport?.ownerAccountID === currentUserPersonalDetails?.accountID; const mergeDuplicates = useCallback(() => { + const transactionThreadReportID = reportAction?.childReportID ?? generateReportID(); + if (!reportAction?.childReportID) { - return; + transactionsMergeParams.transactionThreadReportID = transactionThreadReportID; } + IOU.mergeDuplicates(transactionsMergeParams); if (canUseTableReportView) { Navigation.dismissModal(); return; } - if (!reportAction?.childReportID) { - return; - } - Navigation.dismissModalWithReport({reportID: reportAction.childReportID}); + Navigation.dismissModalWithReport({reportID: transactionThreadReportID}); }, [reportAction?.childReportID, transactionsMergeParams, canUseTableReportView]); const resolveDuplicates = useCallback(() => { diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index e20711e7873b..131d48df37a9 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -41,7 +41,9 @@ import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; import { getCombinedReportActions, getFilteredReportActionsForReportView, + getIOUActionForReportID, getOneTransactionThreadReportID, + getReportAction, isCreatedAction, isDeletedParentAction, isMoneyRequestAction, @@ -49,11 +51,15 @@ import { shouldReportActionBeVisible, } from '@libs/ReportActionsUtils'; import { + buildTransactionThread, canEditReportAction, canUserPerformWriteAction, findLastAccessedReport, + generateReportID, getParticipantsAccountIDsForDisplay, getReportOfflinePendingActionAndErrors, + getReportOrDraftReport, + getReportTransactions, isChatThread, isConciergeChatReport, isGroupChat, @@ -300,6 +306,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { canBeMissing: false, }); const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline); + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, {canBeMissing: true}); const combinedReportActions = getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions)); const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => canEditReportAction(action) && !isMoneyRequestAction(action)); @@ -449,17 +456,30 @@ function ReportScreen({route, navigation}: ReportScreenProps) { return; } - const moneyRequestReportActionID: string | undefined = route.params?.moneyRequestReportActionID; - const transactionID: string | undefined = route.params?.transactionID; + const {moneyRequestReportActionID, transactionID, iouReportID} = route.params; // When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the transaction thread created yet // so we have to call OpenReport in a way that the transaction thread will be created and attached to the parentReportAction - if (transactionID && currentUserEmail) { - openReport(reportIDFromRoute, '', [currentUserEmail], undefined, moneyRequestReportActionID, false, [], undefined, undefined, transactionID); + if (transactionID && currentUserEmail && !report) { + const iouReport = getReportOrDraftReport(iouReportID); + const iouAction = getReportAction(iouReportID, moneyRequestReportActionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, iouReport, undefined, reportIDFromRoute); + openReport(reportIDFromRoute, undefined, [currentUserEmail], optimisticTransactionThread, moneyRequestReportActionID, false, [], undefined, undefined, transactionID); return; } + + // If there is one transaction thread that has not yet been created, we should create it. + if (transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport && currentUserEmail) { + const optimisticTransactionThreadReportID = generateReportID(); + const transactions = getReportTransactions(reportID); + const oneTransactionID = transactions.at(0)?.transactionID; + const iouAction = getIOUActionForReportID(reportID, oneTransactionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, report, undefined, optimisticTransactionThreadReportID); + openReport(optimisticTransactionThreadReportID, undefined, [currentUserEmail], optimisticTransactionThread, iouAction?.reportActionID); + } + openReport(reportIDFromRoute, reportActionIDFromRoute); - }, [reportMetadata.isOptimisticReport, route.params?.moneyRequestReportActionID, route.params?.transactionID, reportIDFromRoute, reportActionIDFromRoute, currentUserEmail]); + }, [reportMetadata.isOptimisticReport, route.params, reportIDFromRoute, reportActionIDFromRoute, currentUserEmail, report, reportID, transactionThreadReport, transactionThreadReportID]); useEffect(() => { if (!reportID || !isFocused) { @@ -525,7 +545,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { // There should be only one openReport execution per page start or navigating fetchReport(); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [route, isLinkedMessagePageReady, reportActionIDFromRoute]); + }, [route, isLinkedMessagePageReady, reportActionIDFromRoute, transactionThreadReportID]); const prevReportActions = usePrevious(reportActions); useEffect(() => { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 2a236649aa07..75d36d9bf31c 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -20,12 +20,13 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useRestoreInputFocus from '@hooks/useRestoreInputFocus'; import useStyleUtils from '@hooks/useStyleUtils'; import {getExpensifyCardFromReportAction} from '@libs/CardMessageUtils'; -import {getLinkedTransactionID, getOneTransactionThreadReportID, getReportAction} from '@libs/ReportActionsUtils'; +import {getLinkedTransactionID, getOneTransactionThreadReportID, getOriginalMessage, getReportActions, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import { chatIncludesChronosWithID, getSourceIDFromReportAction, isArchivedNonExpenseReport, isArchivedNonExpenseReportWithID, + isIOUReport, isInvoiceReport as ReportUtilsIsInvoiceReport, isMoneyRequest as ReportUtilsIsMoneyRequest, isMoneyRequestReport as ReportUtilsIsMoneyRequestReport, @@ -163,7 +164,7 @@ function BaseReportActionContextMenu({ const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {canBeMissing: true}); const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`, {canBeMissing: true}); - const parentReportAction = getReportAction(childReport?.parentReportID, childReport?.parentReportActionID); + const childReportActions = childReport ? getReportActions(childReport) : undefined; const {reportActions: paginatedReportActions} = usePaginatedReportActions(childReport?.reportID); const transactionThreadReportID = useMemo( @@ -178,24 +179,29 @@ function BaseReportActionContextMenu({ const requestParentReportAction = useMemo(() => { if (isMoneyRequestReport || isInvoiceReport) { - if (!paginatedReportActions || !transactionThreadReport?.parentReportActionID) { + if (!paginatedReportActions) { return undefined; } - return paginatedReportActions.find((action) => action.reportActionID === transactionThreadReport.parentReportActionID); + if (transactionThreadReportID === CONST.FAKE_REPORT_ID) { + return Object.values(childReportActions ?? {}).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + } + return paginatedReportActions.find((action) => action.reportActionID === transactionThreadReport?.parentReportActionID); } - return parentReportAction; - }, [parentReportAction, isMoneyRequestReport, isInvoiceReport, paginatedReportActions, transactionThreadReport?.parentReportActionID]); + return reportAction; + }, [childReportActions, transactionThreadReportID, reportAction, isMoneyRequestReport, isInvoiceReport, paginatedReportActions, transactionThreadReport?.parentReportActionID]); - const moneyRequestAction = transactionThreadReportID ? requestParentReportAction : parentReportAction; + const moneyRequestAction = transactionThreadReportID ? requestParentReportAction : reportAction; const [childReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${childReport?.reportID}`, {canBeMissing: true}); const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${childReport?.parentReportID}`, {canBeMissing: true}); - const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${childReport?.parentReportID}`, {canBeMissing: true}); + const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${childReport?.parentReportID ?? (isMoneyRequestAction(reportAction) && getOriginalMessage(reportAction)?.IOUReportID)}`, { + canBeMissing: true, + }); const isMoneyRequest = useMemo(() => ReportUtilsIsMoneyRequest(childReport), [childReport]); const isTrackExpenseReport = ReportUtilsIsTrackExpenseReport(childReport); const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport; - const isMoneyRequestOrReport = isMoneyRequestReport || isSingleTransactionView; + const isMoneyRequestOrReport = isMoneyRequestReport || isSingleTransactionView || isIOUReport(parentReport); const areHoldRequirementsMet = !isInvoiceReport && diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 2d903dbc4b03..2238248163ef 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -111,7 +111,6 @@ import { deleteReportActionDraft, markCommentAsUnread, navigateToAndOpenChildReport, - openReport, readNewestAction, saveReportActionDraft, toggleEmojiReaction, @@ -330,9 +329,8 @@ const ContextMenuActions: ContextMenuAction[] = [ onPress: (closePopover, {reportID, reportAction, draftMessage}) => { if (isMoneyRequestAction(reportAction)) { hideContextMenu(false); - const childReportID = reportAction?.childReportID; - openReport(childReportID); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID)); + const originalReportID = getOriginalReportID(reportID, reportAction); + navigateToAndOpenChildReport(reportAction?.childReportID, reportAction, originalReportID); return; } const editAction = () => { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index ceb95d7f6a5a..a92127f26c89 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -628,8 +628,6 @@ describe('actions/IOU', () => { let createdAction: OnyxEntry; let iouAction: OnyxEntry>; let transactionID: string | undefined; - let transactionThread: OnyxEntry; - let transactionThreadCreatedAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ report: {reportID: ''}, @@ -657,16 +655,14 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connection); - // A chat report, a transaction thread, and an iou report should be created + // A chat report and an iou report should be created const chatReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.CHAT); const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); - expect(Object.keys(chatReports).length).toBe(2); + expect(Object.keys(chatReports).length).toBe(1); expect(Object.keys(iouReports).length).toBe(1); const chatReport = chatReports.at(0); - const transactionThreadReport = chatReports.at(1); const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; - transactionThread = transactionThreadReport; expect(iouReport?.participants).toEqual({ [RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}, @@ -729,29 +725,6 @@ describe('actions/IOU', () => { }); }), ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForTransactionThread) => { - Onyx.disconnect(connection); - - // The transaction thread should have a CREATED action - expect(Object.values(reportActionsForTransactionThread ?? {}).length).toBe(1); - const createdActions = Object.values(reportActionsForTransactionThread ?? {}).filter( - (reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ); - expect(Object.values(createdActions).length).toBe(1); - transactionThreadCreatedAction = createdActions.at(0); - - expect(transactionThreadCreatedAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - resolve(); - }, - }); - }), - ) .then( () => new Promise((resolve) => { @@ -1214,8 +1187,6 @@ describe('actions/IOU', () => { let createdAction: OnyxEntry; let iouAction: OnyxEntry>; let transactionID: string | undefined; - let transactionThreadReport: OnyxEntry; - let transactionThreadAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ report: {reportID: ''}, @@ -1244,14 +1215,13 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connection); - // A chat report, transaction thread and an iou report should be created + // A chat report and an iou report should be created const chatReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.CHAT); const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); - expect(Object.values(chatReports).length).toBe(2); + expect(Object.values(chatReports).length).toBe(1); expect(Object.values(iouReports).length).toBe(1); const chatReport = chatReports.at(0); chatReportID = chatReport?.reportID; - transactionThreadReport = chatReports.at(1); const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; @@ -1364,24 +1334,6 @@ describe('actions/IOU', () => { }); }), ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (reportActionsForTransactionThread) => { - Onyx.disconnect(connection); - expect(Object.values(reportActionsForTransactionThread ?? {}).length).toBe(3); - transactionThreadAction = Object.values( - reportActionsForTransactionThread?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`] ?? {}, - ).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); - expect(transactionThreadAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - resolve(); - }, - }); - }), - ) .then( () => new Promise((resolve) => { @@ -1448,22 +1400,6 @@ describe('actions/IOU', () => { }), ) - // Then the reportAction from transaction report should be removed from Onyx - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForReport) => { - Onyx.disconnect(connection); - expect(reportActionsForReport).toMatchObject({}); - resolve(); - }, - }); - }), - ) - // Along with the associated transaction .then( () => @@ -1487,9 +1423,6 @@ describe('actions/IOU', () => { if (chatReportID) { deleteReport(chatReportID); } - if (transactionThreadReport?.reportID) { - deleteReport(transactionThreadReport?.reportID); - } resolve(); }), )