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

[CP Staging] Fix back navigation after delete expense request in search transcation pane RHP #44372

Merged
merged 2 commits into from
Jun 25, 2024
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
8 changes: 1 addition & 7 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as HeaderUtils from '@libs/HeaderUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand Down Expand Up @@ -378,12 +377,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
isVisible={isDeleteRequestModalVisible}
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteRequestModalVisible(false)}
onModalHide={() => {
if (!navigateBackToAfterDelete.current) {
return;
}
Navigation.goBack(navigateBackToAfterDelete.current);
}}
onModalHide={() => ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current)}
prompt={translate('iou.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down
7 changes: 1 addition & 6 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
isVisible={isDeleteModalVisible}
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteModalVisible(false)}
onModalHide={() => {
if (!navigateBackToAfterDelete.current) {
return;
}
Navigation.goBack(navigateBackToAfterDelete.current);
}}
onModalHide={() => ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current)}
prompt={translate('iou.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down
8 changes: 7 additions & 1 deletion src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import type {EmptyObject} from '@src/types/utils/EmptyObject';
import originalCloseRHPFlow from './closeRHPFlow';
import originalDismissModal from './dismissModal';
import originalDismissModalWithReport from './dismissModalWithReport';
import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute';
import originalGetTopmostReportActionId from './getTopmostReportActionID';
import originalGetTopmostReportId from './getTopmostReportId';
import linkingConfig from './linkingConfig';
import linkTo from './linkTo';
import navigationRef from './navigationRef';
import setNavigationActionToMicrotaskQueue from './setNavigationActionToMicrotaskQueue';
import switchPolicyID from './switchPolicyID';
import type {NavigationStateRoute, State, StateOrRoute, SwitchPolicyIDParams} from './types';
import type {NavigationStateRoute, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types';

let resolveNavigationIsReadyPromise: () => void;
const navigationIsReadyPromise = new Promise<void>((resolve) => {
Expand Down Expand Up @@ -365,6 +366,10 @@ function navigateWithSwitchPolicyID(params: SwitchPolicyIDParams) {
return switchPolicyID(navigationRef.current, params);
}

function getTopMostCentralPaneRouteFromRootState() {
return getTopmostCentralPaneRoute(navigationRef.getRootState() as State<RootStackParamList>);
}

export default {
setShouldPopAllStateOnUP,
navigate,
Expand All @@ -386,6 +391,7 @@ export default {
resetToHome,
closeRHPFlow,
setNavigationActionToMicrotaskQueue,
getTopMostCentralPaneRouteFromRootState,
};

export {navigationRef};
14 changes: 14 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languag
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {
Beta,
OnyxInputOrEntry,
Expand Down Expand Up @@ -3527,6 +3528,18 @@ function goBackToDetailsPage(report: OnyxEntry<Report>) {
Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? '-1'));
}

function navigateBackAfterDeleteTransaction(backRoute: Route | undefined) {
if (!backRoute) {
return;
}
const topmostCentralPaneRoute = Navigation.getTopMostCentralPaneRouteFromRootState();
if (topmostCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) {
Navigation.dismissModal();
return;
}
Navigation.goBack(backRoute);
}

/**
* Go back to the previous page from the edit private page of a given report
*/
Expand Down Expand Up @@ -7263,6 +7276,7 @@ export {
canWriteInReport,
navigateToDetailsPage,
navigateToPrivateNotes,
navigateBackAfterDeleteTransaction,
parseReportRouteParams,
parseReportActionHtmlToText,
reportFieldsEnabled,
Expand Down
7 changes: 1 addition & 6 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
isVisible={isDeleteModalVisible}
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteModalVisible(false)}
onModalHide={() => {
if (!navigateBackToAfterDelete.current) {
return;
}
Navigation.goBack(navigateBackToAfterDelete.current);
}}
onModalHide={() => ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current)}
prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ function ReportScreen({
isClosedTopLevelPolicyRoom
) {
// Early return if the report we're passing isn't in a focused state. We only want to navigate to Concierge if the user leaves the room from another device or gets removed from the room while the report is in a focused state.
if (!isFocused) {
// Prevent auto navigation for report in RHP
if (!isFocused || isReportOpenInRHP) {
return;
}
Navigation.dismissModal();
Expand Down Expand Up @@ -581,6 +582,7 @@ function ReportScreen({

fetchReportIfNeeded();
ComposerActions.setShouldShowComposeInput(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
route,
report,
Expand Down
Loading