Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search v2.1] Keep user on search page if expense is created from Search page #47721

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
22 changes: 22 additions & 0 deletions src/libs/Navigation/isSearchTopmostCentralPane.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SCREENS from '@src/SCREENS';
import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute';
import {navigationRef} from './Navigation';
import type {RootStackParamList, State} from './types';

const isSearchTopmostCentralPane = (): boolean => {
const rootState = navigationRef.getRootState() as State<RootStackParamList>;

if (!rootState) {
return false;
}

const topmostCentralPaneRoute = getTopmostCentralPaneRoute(rootState);

if (topmostCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) {
return true;
}

return false;
};

export default isSearchTopmostCentralPane;
24 changes: 15 additions & 9 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils';
import * as IOUUtils from '@libs/IOUUtils';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane';
import Navigation from '@libs/Navigation/Navigation';
import * as NextStepUtils from '@libs/NextStepUtils';
import {rand64} from '@libs/NumberUtils';
Expand Down Expand Up @@ -3587,7 +3588,7 @@ function requestMoney(
}
}

Navigation.dismissModal(activeReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);
if (activeReportID) {
Report.notifyNewAction(activeReportID, payeeAccountID);
}
Expand Down Expand Up @@ -3629,7 +3630,12 @@ function sendInvoice(

API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData);

Navigation.dismissModalWithReport(invoiceRoom);
if (isSearchTopmostCentralPane()) {
Navigation.dismissModal();
} else {
Navigation.dismissModalWithReport(invoiceRoom);
}

Report.notifyNewAction(invoiceRoom.reportID, receiver.accountID);
}

Expand Down Expand Up @@ -3807,7 +3813,7 @@ function trackExpense(
API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData);
}
}
Navigation.dismissModal(activeReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);

if (action === CONST.IOU.ACTION.SHARE) {
Navigation.navigate(ROUTES.ROOM_INVITE.getRoute(activeReportID ?? '-1', CONST.IOU.SHARE.ROLE.ACCOUNTANT));
Expand Down Expand Up @@ -4373,7 +4379,7 @@ function splitBill({

API.write(WRITE_COMMANDS.SPLIT_BILL, parameters, onyxData);

Navigation.dismissModal(existingSplitChatReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : existingSplitChatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
}

Expand Down Expand Up @@ -4440,7 +4446,7 @@ function splitBillAndOpenReport({

API.write(WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, parameters, onyxData);

Navigation.dismissModal(splitData.chatReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : splitData.chatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
}

Expand Down Expand Up @@ -4994,7 +5000,7 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA
};

API.write(WRITE_COMMANDS.COMPLETE_SPLIT_BILL, parameters, {optimisticData, successData, failureData});
Navigation.dismissModal(chatReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : chatReportID);
Report.notifyNewAction(chatReportID, sessionAccountID);
}

Expand Down Expand Up @@ -5153,7 +5159,7 @@ function createDistanceRequest(

API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData);
const activeReportID = isMoneyRequestReport ? report?.reportID ?? '-1' : parameters.chatReportID;
Navigation.dismissModal(activeReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);
Report.notifyNewAction(activeReportID, userAccountID);
}

Expand Down Expand Up @@ -6754,7 +6760,7 @@ function sendMoneyElsewhere(report: OnyxEntry<OnyxTypes.Report>, amount: number,

API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData});

Navigation.dismissModal(params.chatReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : params.chatReportID);
Report.notifyNewAction(params.chatReportID, managerID);
}

Expand All @@ -6767,7 +6773,7 @@ function sendMoneyWithWallet(report: OnyxEntry<OnyxTypes.Report>, amount: number

API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData});

Navigation.dismissModal(params.chatReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : params.chatReportID);
Report.notifyNewAction(params.chatReportID, managerID);
}

Expand Down
5 changes: 3 additions & 2 deletions src/pages/EditReportFieldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as ReportActions from '@src/libs/actions/Report';
Expand Down Expand Up @@ -80,14 +81,14 @@ function EditReportFieldPage({route, policy, report}: EditReportFieldPageProps)
Navigation.goBack();
} else {
ReportActions.updateReportField(report.reportID, {...reportField, value: value === '' ? null : value}, reportField);
Navigation.dismissModal(report?.reportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : report?.reportID);
}
};

const handleReportFieldDelete = () => {
ReportActions.deleteReportField(report.reportID, reportField);
setIsDeleteModalVisible(false);
Navigation.dismissModal(report?.reportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : report?.reportID);
};

const fieldValue = isReportFieldTitle ? report.reportName ?? '' : reportField.value ?? reportField.defaultValue;
Expand Down
2 changes: 2 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jest.mock('@src/libs/Navigation/Navigation', () => ({
goBack: jest.fn(),
}));

jest.mock('@src/libs/Navigation/isSearchTopmostCentralPane', () => jest.fn());

const CARLOS_EMAIL = 'cmartins@expensifail.com';
const CARLOS_ACCOUNT_ID = 1;
const CARLOS_PARTICIPANT: Participant = {hidden: false, role: 'member'};
Expand Down
Loading