Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/libs/actions/IOU/NavigationHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import sharedDismissModalAndOpenReportInInboxTab from '@libs/Navigation/helpers/dismissModalAndOpenReportInInboxTab';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
import navigateAfterExpenseCreate from '@libs/Navigation/helpers/navigateAfterExpenseCreate';
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
import {getAllTransactions} from './index';

/**
* @private
* After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report.
* If the action is done from the report RHP, then we just want to dismiss the money request flow screens.
* It is a helper function used only in this file.
*/
function dismissModalAndOpenReportInInboxTab(reportID?: string, isInvoice?: boolean) {
const hasMultipleTransactions = Object.values(getAllTransactions()).filter((transaction) => transaction?.reportID === reportID).length > 0;
sharedDismissModalAndOpenReportInInboxTab(reportID, isInvoice, hasMultipleTransactions);
}

/**
* Marks a transaction for highlight on the Search page when the expense was created
* from the global create button and the user is not on the Inbox tab.
*/
function highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate: boolean | undefined, transactionID: string | undefined, dataType: SearchDataTypes) {
if (!isFromGlobalCreate || isReportTopmostSplitNavigator() || !transactionID) {
return;
}
mergeTransactionIdsHighlightOnSearchRoute(dataType, {[transactionID]: true});
}

/**
* Helper to navigate after an expense is created in order to standardize the post‑creation experience
* when creating an expense from the global create button.
* If the expense is created from the global create button then:
* - If it is created on the inbox tab, it will open the chat report containing that expense.
* - If it is created elsewhere, it will navigate to Reports > Expense and highlight the newly created expense.
*/
function handleNavigateAfterExpenseCreate({
activeReportID,
transactionID,
isFromGlobalCreate,
isInvoice,
}: {
activeReportID?: string;
transactionID?: string;
isFromGlobalCreate?: boolean;
isInvoice?: boolean;
}) {
const hasMultipleTransactions = Object.values(getAllTransactions()).filter((transaction) => transaction?.reportID === activeReportID).length > 0;
navigateAfterExpenseCreate({activeReportID, transactionID, isFromGlobalCreate, isInvoice, hasMultipleTransactions});
}

export {dismissModalAndOpenReportInInboxTab, handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded};
3 changes: 1 addition & 2 deletions src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {
buildMinimalTransactionForFormula,
buildOnyxDataForMoneyRequest,
dismissModalAndOpenReportInInboxTab,
getAllPersonalDetails,
getAllReports,
getPolicyTags,
getReportPreviewAction,
highlightTransactionOnSearchRouteIfNeeded,
mergePolicyRecentlyUsedCategories,
mergePolicyRecentlyUsedCurrencies,
} from '.';
import type {BaseTransactionParams, MoneyRequestInformation, RequestMoneyParticipantParams} from './index';
import {dismissModalAndOpenReportInInboxTab, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
import type BasePolicyParams from './types/BasePolicyParams';

function removeSubrate(transaction: OnyxEntry<OnyxTypes.Transaction>, currentIndex: string) {
Expand Down
11 changes: 2 additions & 9 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'
import type {OnyxData} from '@src/types/onyx/Request';
import type {Receipt} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {
getAllPersonalDetails,
getReceiptError,
getSearchOnyxUpdate,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
mergePolicyRecentlyUsedCategories,
mergePolicyRecentlyUsedCurrencies,
} from '.';
import {getAllPersonalDetails, getReceiptError, getSearchOnyxUpdate, mergePolicyRecentlyUsedCategories, mergePolicyRecentlyUsedCurrencies} from '.';
import {handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
import type BasePolicyParams from './types/BasePolicyParams';

type SendInvoiceInformation = {
Expand Down
4 changes: 1 addition & 3 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {
buildMinimalTransactionForFormula,
buildOnyxDataForMoneyRequest,
dismissModalAndOpenReportInInboxTab,
getAllPersonalDetails,
getAllReports,
getAllTransactionDrafts,
Expand All @@ -80,12 +79,11 @@ import {
getReceiptError,
getReportPreviewAction,
getUserAccountID,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
mergePolicyRecentlyUsedCategories,
mergePolicyRecentlyUsedCurrencies,
} from './index';
import type {BuildOnyxDataForMoneyRequestKeys, OneOnOneIOUReport, StartSplitBilActionParams} from './index';
import {dismissModalAndOpenReportInInboxTab, handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
import type BasePolicyParams from './types/BasePolicyParams';
import type BaseTransactionParams from './types/BaseTransactionParams';

Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/IOU/TrackExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ import {
getReportPreviewAction,
getSearchOnyxUpdate,
getTransactionWithPreservedLocalReceiptSource,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
} from './index';
import {handleNavigateAfterExpenseCreate, highlightTransactionOnSearchRouteIfNeeded} from './NavigationHelpers';
import type BasePolicyParams from './types/BasePolicyParams';
import type {CreateTrackExpenseParams} from './types/CreateTrackExpenseParams';
import type {
Expand Down
53 changes: 1 addition & 52 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import {formatCurrentUserToAttendee, updateIOUOwnerAndTotal} from '@libs/IOUUtil
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
import Log from '@libs/Log';
import sharedDismissModalAndOpenReportInInboxTab from '@libs/Navigation/helpers/dismissModalAndOpenReportInInboxTab';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
import navigateAfterExpenseCreate from '@libs/Navigation/helpers/navigateAfterExpenseCreate';
import Navigation from '@libs/Navigation/Navigation';
import {buildNextStepNew, buildOptimisticNextStep} from '@libs/NextStepUtils';
import * as NumberUtils from '@libs/NumberUtils';
Expand Down Expand Up @@ -74,7 +71,6 @@ import {
} from '@libs/TransactionUtils';
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import {mergeTransactionIdsHighlightOnSearchRoute} from '@userActions/Transaction';
import {getRemoveDraftTransactionsByIDsData, removeDraftTransactionsByIDs} from '@userActions/TransactionEdit';
import type {IOUAction, IOUActionParams} from '@src/CONST';
import CONST from '@src/CONST';
Expand All @@ -89,7 +85,7 @@ import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
import type {ReportNextStep} from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import type {SearchDataTypes, SearchResultDataType} from '@src/types/onyx/SearchResults';
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
import type {Comment, Receipt, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type BasePolicyParams from './types/BasePolicyParams';
Expand Down Expand Up @@ -528,50 +524,6 @@ function getMoneyRequestPolicyTags({
return getPolicyTagsData(iouReportPolicyID) ?? {};
}

/**
* @private
* After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report.
* If the action is done from the report RHP, then we just want to dismiss the money request flow screens.
* It is a helper function used only in this file.
*/
function dismissModalAndOpenReportInInboxTab(reportID?: string, isInvoice?: boolean) {
const hasMultipleTransactions = Object.values(allTransactions).filter((transaction) => transaction?.reportID === reportID).length > 0;
sharedDismissModalAndOpenReportInInboxTab(reportID, isInvoice, hasMultipleTransactions);
}

/**
* Marks a transaction for highlight on the Search page when the expense was created
* from the global create button and the user is not on the Inbox tab.
*/
function highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate: boolean | undefined, transactionID: string | undefined, dataType: SearchDataTypes) {
if (!isFromGlobalCreate || isReportTopmostSplitNavigator() || !transactionID) {
return;
}
mergeTransactionIdsHighlightOnSearchRoute(dataType, {[transactionID]: true});
}

/**
* Helper to navigate after an expense is created in order to standardize the post‑creation experience
* when creating an expense from the global create button.
* If the expense is created from the global create button then:
* - If it is created on the inbox tab, it will open the chat report containing that expense.
* - If it is created elsewhere, it will navigate to Reports > Expense and highlight the newly created expense.
*/
function handleNavigateAfterExpenseCreate({
activeReportID,
transactionID,
isFromGlobalCreate,
isInvoice,
}: {
activeReportID?: string;
transactionID?: string;
isFromGlobalCreate?: boolean;
isInvoice?: boolean;
}) {
const hasMultipleTransactions = Object.values(allTransactions).filter((transaction) => transaction?.reportID === activeReportID).length > 0;
navigateAfterExpenseCreate({activeReportID, transactionID, isFromGlobalCreate, isInvoice, hasMultipleTransactions});
}

/**
* Build a minimal transaction record for formula computation in buildOptimisticExpenseReport.
* This allows formulas like {report:startdate}, {report:expensescount} to work correctly.
Expand Down Expand Up @@ -2724,7 +2676,6 @@ export {
createDraftTransaction,
getIOURequestPolicyID,
initMoneyRequest,
dismissModalAndOpenReportInInboxTab,
resetDraftTransactionsCustomUnit,
setCustomUnitRateID,
setGPSTransactionDraftData,
Expand Down Expand Up @@ -2782,12 +2733,10 @@ export {
getMoneyRequestPolicyTags,
setMoneyRequestTimeRate,
setMoneyRequestTimeCount,
handleNavigateAfterExpenseCreate,
buildMinimalTransactionForFormula,
buildOnyxDataForMoneyRequest,
getMoneyRequestInformation,
getTransactionWithPreservedLocalReceiptSource,
highlightTransactionOnSearchRouteIfNeeded,
};
export type {
GPSPoint as GpsPoint,
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import useOnyx from '@hooks/useOnyx';
import {clearAllRelatedReportActionErrors} from '@libs/actions/ClearReportActionErrors';
import {
calculateDiffAmount,
handleNavigateAfterExpenseCreate,
initMoneyRequest,
resetDraftTransactionsCustomUnit,
setMoneyRequestAmount,
Expand All @@ -24,6 +23,7 @@ import {
shouldOptimisticallyUpdateSearch,
} from '@libs/actions/IOU';
import {putOnHold} from '@libs/actions/IOU/Hold';
import {handleNavigateAfterExpenseCreate} from '@libs/actions/IOU/NavigationHelpers';
import {completeSplitBill, splitBill, startSplitBill} from '@libs/actions/IOU/Split';
import {updateSplitTransactionsFromSplitExpensesFlow} from '@libs/actions/IOU/SplitTransactionUpdate';
import {requestMoney, trackExpense} from '@libs/actions/IOU/TrackExpense';
Expand Down
Loading