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
4 changes: 4 additions & 0 deletions src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
getReportPreviewAction,
getUserAccountID,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
mergePolicyRecentlyUsedCategories,
mergePolicyRecentlyUsedCurrencies,
} from '.';
Expand Down Expand Up @@ -999,6 +1000,9 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf

// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, transaction.transactionID, CONST.SEARCH.DATA_TYPES.EXPENSE);

handleNavigateAfterExpenseCreate({activeReportID, transactionID: transaction.transactionID, isFromGlobalCreate, shouldHandleNavigation});

if (activeReportID) {
Expand Down
3 changes: 3 additions & 0 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getReceiptError,
getSearchOnyxUpdate,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
mergePolicyRecentlyUsedCategories,
mergePolicyRecentlyUsedCurrencies,
} from '.';
Expand Down Expand Up @@ -818,6 +819,8 @@ function sendInvoice({
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, transactionID, CONST.SEARCH.DATA_TYPES.INVOICE);

handleNavigateAfterExpenseCreate({
activeReportID: invoiceRoom.reportID,
transactionID,
Expand Down
25 changes: 20 additions & 5 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@
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} from '@src/types/onyx/SearchResults';
import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {resolveDetachReceiptConflicts} from '../RequestConflictUtils';

Check warning on line 265 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../RequestConflictUtils'. Use '@userActions/RequestConflictUtils' instead

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

Expand Down Expand Up @@ -779,7 +780,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 783 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -909,7 +910,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 913 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -923,7 +924,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 927 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -932,7 +933,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 936 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -946,7 +947,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 950 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -959,7 +960,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 963 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -968,7 +969,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 972 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -978,7 +979,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 982 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -987,7 +988,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 991 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -1142,6 +1143,17 @@
}
}

/**
* 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.
Expand Down Expand Up @@ -1174,15 +1186,12 @@
return;
}

const type = isInvoice ? CONST.SEARCH.DATA_TYPES.INVOICE : CONST.SEARCH.DATA_TYPES.EXPENSE;

// We mark this transaction to be highlighted when opening the expense search route page
mergeTransactionIdsHighlightOnSearchRoute(type, {[transactionID]: true});

if (!shouldHandleNavigation) {
return;
}

const type = isInvoice ? CONST.SEARCH.DATA_TYPES.INVOICE : CONST.SEARCH.DATA_TYPES.EXPENSE;

// When already on Search ROOT with the same type (expense vs invoice), we navigate to the same screen (no-op or refresh); record as dismiss_modal_only.
// When on another Search sub-tab (e.g. Chats), or on Search with a different type (e.g. on Invoice, submitting expense), record as navigate_to_search.
const rootState = navigationRef.getRootState();
Expand Down Expand Up @@ -6607,6 +6616,8 @@
}

if (!requestMoneyInformation.isRetry) {
highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, transaction.transactionID, CONST.SEARCH.DATA_TYPES.EXPENSE);

handleNavigateAfterExpenseCreate({
activeReportID: backToReport ?? activeReportID,
transactionID: transaction.transactionID,
Expand Down Expand Up @@ -6991,6 +7002,8 @@
}

if (!params.isRetry) {
highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, transaction?.transactionID, CONST.SEARCH.DATA_TYPES.EXPENSE);

handleNavigateAfterExpenseCreate({
activeReportID,
transactionID: transaction?.transactionID,
Expand Down Expand Up @@ -7851,6 +7864,7 @@
const activeReportID = isMoneyRequestReport && report?.reportID ? report.reportID : parameters.chatReportID;

if (shouldHandleNavigation) {
highlightTransactionOnSearchRouteIfNeeded(isFromGlobalCreate, parameters.transactionID, CONST.SEARCH.DATA_TYPES.EXPENSE);
handleNavigateAfterExpenseCreate({activeReportID: backToReport ?? activeReportID, isFromGlobalCreate, transactionID: parameters.transactionID});
}

Expand Down Expand Up @@ -13279,6 +13293,7 @@
setMoneyRequestTimeCount,
getCleanUpTransactionThreadReportOnyxData,
handleNavigateAfterExpenseCreate,
highlightTransactionOnSearchRouteIfNeeded,
buildMinimalTransactionForFormula,
buildOnyxDataForMoneyRequest,
createSplitsAndOnyxData,
Expand Down
14 changes: 2 additions & 12 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14989,9 +14989,6 @@ describe('actions/IOU', () => {
const transactionID = '1';
mockedIsReportTopmostSplitNavigator.mockReturnValue(false);

// When on the Inbox tab, or NOT from the "global create" button, or without a transactionID,
// the function dismissModalAndOpenReportInInboxTab will always be called to handle it,
// so mergeTransactionIdsHighlightOnSearchRoute will never be invoked.
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: false});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

Expand All @@ -15002,20 +14999,13 @@ describe('actions/IOU', () => {
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

// When NOT on the Inbox tab
mockedIsReportTopmostSplitNavigator.mockReturnValue(false);
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

// then mergeTransactionIdsHighlightOnSearchRoute will be called
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(1);
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledWith(CONST.SEARCH.DATA_TYPES.EXPENSE, {[transactionID]: true});
spyOnMergeTransactionIdsHighlightOnSearchRoute.mockClear();

// If expense is an invoice
handleNavigateAfterExpenseCreate({activeReportID, isFromGlobalCreate: true, transactionID, isInvoice: true});
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(0);

expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledTimes(1);
expect(spyOnMergeTransactionIdsHighlightOnSearchRoute).toHaveBeenCalledWith(CONST.SEARCH.DATA_TYPES.INVOICE, {[transactionID]: true});
spyOnMergeTransactionIdsHighlightOnSearchRoute.mockReset();
});

Expand Down
Loading