Skip to content

Commit

Permalink
Merge pull request #47721 from software-mansion-labs/adamgrzybowski/k…
Browse files Browse the repository at this point in the history
…eep-user-on-search-page

[Search v2.1] Keep user on search page if expense is created from Search page
  • Loading branch information
luacmartins authored Aug 23, 2024
2 parents 28fbed6 + 9e1b2db commit 64cdaad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
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 @@ -3571,7 +3572,7 @@ function requestMoney(
}
}

Navigation.dismissModal(activeReportID);
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);
if (activeReportID) {
Report.notifyNewAction(activeReportID, payeeAccountID);
}
Expand Down Expand Up @@ -3628,7 +3629,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 @@ -3806,7 +3812,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 @@ -4372,7 +4378,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 @@ -4439,7 +4445,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 @@ -4993,7 +4999,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 @@ -5152,7 +5158,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 @@ -6753,7 +6759,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 @@ -6766,7 +6772,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

0 comments on commit 64cdaad

Please sign in to comment.