Skip to content

Commit 17d2bb7

Browse files
committed
refactor: extract NavigationHelpers.ts from IOU/index.ts
Extracts post-expense-creation navigation helpers (dismissModalAndOpenReportInInboxTab, highlightTransactionOnSearchRouteIfNeeded, handleNavigateAfterExpenseCreate) into a dedicated module to reduce the size of IOU/index.ts. Function bodies are byte-identical to their pre-move state on main, with the single required translation of direct allTransactions reads to getAllTransactions() calls (needed because allTransactions is module-private to index.ts). Part of Issue #72804 (break up src/libs/actions/IOU/).
1 parent 589e414 commit 17d2bb7

7 files changed

Lines changed: 59 additions & 69 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sharedDismissModalAndOpenReportInInboxTab from '@libs/Navigation/helpers/dismissModalAndOpenReportInInboxTab';
2+
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
3+
import navigateAfterExpenseCreate from '@libs/Navigation/helpers/navigateAfterExpenseCreate';
4+
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
5+
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
6+
import {getAllTransactions} from './index';
7+
8+
/**
9+
* @private
10+
* After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report.
11+
* If the action is done from the report RHP, then we just want to dismiss the money request flow screens.
12+
* It is a helper function used only in this file.
13+
*/
14+
function dismissModalAndOpenReportInInboxTab(reportID?: string, isInvoice?: boolean) {
15+
const hasMultipleTransactions = Object.values(getAllTransactions()).filter((transaction) => transaction?.reportID === reportID).length > 0;
16+
sharedDismissModalAndOpenReportInInboxTab(reportID, isInvoice, hasMultipleTransactions);
17+
}
18+
19+
/**
20+
* Marks a transaction for highlight on the Search page when the expense was created
21+
* from the global create button and the user is not on the Inbox tab.
22+
*/
23+
function highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate: boolean | undefined, transactionID: string | undefined, dataType: SearchDataTypes) {
24+
if (!isFromGlobalCreate || isReportTopmostSplitNavigator() || !transactionID) {
25+
return;
26+
}
27+
mergeTransactionIdsHighlightOnSearchRoute(dataType, {[transactionID]: true});
28+
}
29+
30+
/**
31+
* Helper to navigate after an expense is created in order to standardize the post‑creation experience
32+
* when creating an expense from the global create button.
33+
* If the expense is created from the global create button then:
34+
* - If it is created on the inbox tab, it will open the chat report containing that expense.
35+
* - If it is created elsewhere, it will navigate to Reports > Expense and highlight the newly created expense.
36+
*/
37+
function handleNavigateAfterExpenseCreate({
38+
activeReportID,
39+
transactionID,
40+
isFromGlobalCreate,
41+
isInvoice,
42+
}: {
43+
activeReportID?: string;
44+
transactionID?: string;
45+
isFromGlobalCreate?: boolean;
46+
isInvoice?: boolean;
47+
}) {
48+
const hasMultipleTransactions = Object.values(getAllTransactions()).filter((transaction) => transaction?.reportID === activeReportID).length > 0;
49+
navigateAfterExpenseCreate({activeReportID, transactionID, isFromGlobalCreate, isInvoice, hasMultipleTransactions});
50+
}
51+
52+
export {dismissModalAndOpenReportInInboxTab, handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded};

src/libs/actions/IOU/PerDiem.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
5252
import {
5353
buildMinimalTransactionForFormula,
5454
buildOnyxDataForMoneyRequest,
55-
dismissModalAndOpenReportInInboxTab,
5655
getAllPersonalDetails,
5756
getAllReports,
5857
getPolicyTags,
5958
getReportPreviewAction,
60-
highlightTransactionOnSearchRouteIfNeeded,
6159
mergePolicyRecentlyUsedCategories,
6260
mergePolicyRecentlyUsedCurrencies,
6361
} from '.';
6462
import type {BaseTransactionParams, MoneyRequestInformation, RequestMoneyParticipantParams} from './index';
63+
import {dismissModalAndOpenReportInInboxTab, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
6564
import type BasePolicyParams from './types/BasePolicyParams';
6665

6766
function removeSubrate(transaction: OnyxEntry<OnyxTypes.Transaction>, currentIndex: string) {

src/libs/actions/IOU/SendInvoice.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,8 @@ import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'
3535
import type {OnyxData} from '@src/types/onyx/Request';
3636
import type {Receipt} from '@src/types/onyx/Transaction';
3737
import {isEmptyObject} from '@src/types/utils/EmptyObject';
38-
import {
39-
getAllPersonalDetails,
40-
getReceiptError,
41-
getSearchOnyxUpdate,
42-
handleNavigateAfterExpenseCreate,
43-
highlightTransactionOnSearchRouteIfNeeded,
44-
mergePolicyRecentlyUsedCategories,
45-
mergePolicyRecentlyUsedCurrencies,
46-
} from '.';
38+
import {getAllPersonalDetails, getReceiptError, getSearchOnyxUpdate, mergePolicyRecentlyUsedCategories, mergePolicyRecentlyUsedCurrencies} from '.';
39+
import {handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
4740
import type BasePolicyParams from './types/BasePolicyParams';
4841

4942
type SendInvoiceInformation = {

src/libs/actions/IOU/Split.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
6969
import {
7070
buildMinimalTransactionForFormula,
7171
buildOnyxDataForMoneyRequest,
72-
dismissModalAndOpenReportInInboxTab,
7372
getAllPersonalDetails,
7473
getAllReports,
7574
getAllTransactionDrafts,
@@ -80,12 +79,11 @@ import {
8079
getReceiptError,
8180
getReportPreviewAction,
8281
getUserAccountID,
83-
handleNavigateAfterExpenseCreate,
84-
highlightTransactionOnSearchRouteIfNeeded,
8582
mergePolicyRecentlyUsedCategories,
8683
mergePolicyRecentlyUsedCurrencies,
8784
} from './index';
8885
import type {BuildOnyxDataForMoneyRequestKeys, OneOnOneIOUReport, StartSplitBilActionParams} from './index';
86+
import {dismissModalAndOpenReportInInboxTab, handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
8987
import type BasePolicyParams from './types/BasePolicyParams';
9088
import type BaseTransactionParams from './types/BaseTransactionParams';
9189

src/libs/actions/IOU/TrackExpense.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ import {
117117
getReportPreviewAction,
118118
getSearchOnyxUpdate,
119119
getTransactionWithPreservedLocalReceiptSource,
120-
handleNavigateAfterExpenseCreate,
121-
highlightTransactionOnSearchRouteIfNeeded,
122120
} from './index';
121+
import {handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
123122
import type BasePolicyParams from './types/BasePolicyParams';
124123
import type {CreateTrackExpenseParams} from './types/CreateTrackExpenseParams';
125124
import type {

src/libs/actions/IOU/index.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import {formatCurrentUserToAttendee, updateIOUOwnerAndTotal} from '@libs/IOUUtil
1515
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
1616
import * as Localize from '@libs/Localize';
1717
import Log from '@libs/Log';
18-
import sharedDismissModalAndOpenReportInInboxTab from '@libs/Navigation/helpers/dismissModalAndOpenReportInInboxTab';
19-
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
20-
import navigateAfterExpenseCreate from '@libs/Navigation/helpers/navigateAfterExpenseCreate';
2118
import Navigation from '@libs/Navigation/Navigation';
2219
import {buildNextStepNew, buildOptimisticNextStep} from '@libs/NextStepUtils';
2320
import * as NumberUtils from '@libs/NumberUtils';
@@ -74,7 +71,6 @@ import {
7471
} from '@libs/TransactionUtils';
7572
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
7673
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
77-
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
7874
import {getRemoveDraftTransactionsByIDsData, removeDraftTransactionsByIDs} from '@userActions/TransactionEdit';
7975
import type {IOUAction, IOUActionParams} from '@src/CONST';
8076
import CONST from '@src/CONST';
@@ -89,7 +85,7 @@ import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
8985
import type {ReportNextStep} from '@src/types/onyx/Report';
9086
import type ReportAction from '@src/types/onyx/ReportAction';
9187
import type {OnyxData} from '@src/types/onyx/Request';
92-
import type {SearchDataTypes, SearchResultDataType} from '@src/types/onyx/SearchResults';
88+
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
9389
import type {Comment, Receipt, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
9490
import {isEmptyObject} from '@src/types/utils/EmptyObject';
9591
import type BasePolicyParams from './types/BasePolicyParams';
@@ -528,50 +524,6 @@ function getMoneyRequestPolicyTags({
528524
return getPolicyTagsData(iouReportPolicyID) ?? {};
529525
}
530526

531-
/**
532-
* @private
533-
* After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report.
534-
* If the action is done from the report RHP, then we just want to dismiss the money request flow screens.
535-
* It is a helper function used only in this file.
536-
*/
537-
function dismissModalAndOpenReportInInboxTab(reportID?: string, isInvoice?: boolean) {
538-
const hasMultipleTransactions = Object.values(allTransactions).filter((transaction) => transaction?.reportID === reportID).length > 0;
539-
sharedDismissModalAndOpenReportInInboxTab(reportID, isInvoice, hasMultipleTransactions);
540-
}
541-
542-
/**
543-
* Marks a transaction for highlight on the Search page when the expense was created
544-
* from the global create button and the user is not on the Inbox tab.
545-
*/
546-
function highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate: boolean | undefined, transactionID: string | undefined, dataType: SearchDataTypes) {
547-
if (!isFromGlobalCreate || isReportTopmostSplitNavigator() || !transactionID) {
548-
return;
549-
}
550-
mergeTransactionIdsHighlightOnSearchRoute(dataType, {[transactionID]: true});
551-
}
552-
553-
/**
554-
* Helper to navigate after an expense is created in order to standardize the post‑creation experience
555-
* when creating an expense from the global create button.
556-
* If the expense is created from the global create button then:
557-
* - If it is created on the inbox tab, it will open the chat report containing that expense.
558-
* - If it is created elsewhere, it will navigate to Reports > Expense and highlight the newly created expense.
559-
*/
560-
function handleNavigateAfterExpenseCreate({
561-
activeReportID,
562-
transactionID,
563-
isFromGlobalCreate,
564-
isInvoice,
565-
}: {
566-
activeReportID?: string;
567-
transactionID?: string;
568-
isFromGlobalCreate?: boolean;
569-
isInvoice?: boolean;
570-
}) {
571-
const hasMultipleTransactions = Object.values(allTransactions).filter((transaction) => transaction?.reportID === activeReportID).length > 0;
572-
navigateAfterExpenseCreate({activeReportID, transactionID, isFromGlobalCreate, isInvoice, hasMultipleTransactions});
573-
}
574-
575527
/**
576528
* Build a minimal transaction record for formula computation in buildOptimisticExpenseReport.
577529
* This allows formulas like {report:startdate}, {report:expensescount} to work correctly.
@@ -2724,7 +2676,6 @@ export {
27242676
createDraftTransaction,
27252677
getIOURequestPolicyID,
27262678
initMoneyRequest,
2727-
dismissModalAndOpenReportInInboxTab,
27282679
resetDraftTransactionsCustomUnit,
27292680
setCustomUnitRateID,
27302681
setGPSTransactionDraftData,
@@ -2782,12 +2733,10 @@ export {
27822733
getMoneyRequestPolicyTags,
27832734
setMoneyRequestTimeRate,
27842735
setMoneyRequestTimeCount,
2785-
handleNavigateAfterExpenseCreate,
27862736
buildMinimalTransactionForFormula,
27872737
buildOnyxDataForMoneyRequest,
27882738
getMoneyRequestInformation,
27892739
getTransactionWithPreservedLocalReceiptSource,
2790-
highlightTransactionOnSearchRouteIfNeeded,
27912740
};
27922741
export type {
27932742
GPSPoint as GpsPoint,

tests/actions/IOUTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import useOnyx from '@hooks/useOnyx';
99
import {clearAllRelatedReportActionErrors} from '@libs/actions/ClearReportActionErrors';
1010
import {
1111
calculateDiffAmount,
12-
handleNavigateAfterExpenseCreate,
1312
initMoneyRequest,
1413
resetDraftTransactionsCustomUnit,
1514
setMoneyRequestAmount,
@@ -24,6 +23,7 @@ import {
2423
shouldOptimisticallyUpdateSearch,
2524
} from '@libs/actions/IOU';
2625
import {putOnHold} from '@libs/actions/IOU/Hold';
26+
import {handleNavigateAfterExpenseCreate} from '@libs/actions/IOU/NavigationHelpers';
2727
import {completeSplitBill, splitBill, startSplitBill} from '@libs/actions/IOU/Split';
2828
import {updateSplitTransactionsFromSplitExpensesFlow} from '@libs/actions/IOU/SplitTransactionUpdate';
2929
import {requestMoney, trackExpense} from '@libs/actions/IOU/TrackExpense';

0 commit comments

Comments
 (0)