Skip to content

Commit

Permalink
Merge pull request Expensify#44359 from Krishna2323/krishna2323/issue…
Browse files Browse the repository at this point in the history
…/44337

[CP Staging] fix: Search - Transaction RHP dismisses when holding/unholding expense from report details page.
  • Loading branch information
mountiny authored Jun 25, 2024
2 parents 8c5f325 + 0518e61 commit fb43f88
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
20 changes: 17 additions & 3 deletions src/components/PromotedActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as HeaderUtils from '@libs/HeaderUtils';
import * as Localize from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {CentralPaneNavigatorParamList, RootStackParamList, State} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import * as ReportActions from '@userActions/Report';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {ReportAction} from '@src/types/onyx';
import type OnyxReport from '@src/types/onyx/Report';
import Button from './Button';
Expand Down Expand Up @@ -66,8 +70,18 @@ const PromotedActions = {
icon: Expensicons.Stopwatch,
text: Localize.translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`),
onSelected: () => {
Navigation.dismissModal();
ReportUtils.changeMoneyRequestHoldStatus(reportAction);
if (!isTextHold) {
Navigation.goBack();
}
const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State<RootStackParamList>);

if (topmostCentralPaneRoute?.name !== SCREENS.SEARCH.CENTRAL_PANE && isTextHold) {
ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.REPORT_WITH_ID.getRoute(reportAction?.childReportID ?? ''));
return;
}

const currentQuery = topmostCentralPaneRoute?.params as CentralPaneNavigatorParamList['Search_Central_Pane'];
ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(currentQuery?.query ?? CONST.SEARCH.TAB.ALL, reportAction?.childReportID ?? ''));
},
}),
} satisfies PromotedActionsType;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
return {canHoldRequest, canUnholdRequest};
}

const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>): void => {
const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, backTo?: string): void => {
if (!ReportActionsUtils.isMoneyRequestAction(reportAction)) {
return;
}
Expand All @@ -2804,7 +2804,8 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>): vo
IOU.unholdRequest(transactionID, reportAction.childReportID ?? '');
} else {
const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams());
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', activeRoute));
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/HoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
>
<HeaderWithBackButton
title={translate('iou.holdExpense')}
onBackButtonPress={navigateBack}
onBackButtonPress={() => Navigation.goBack(backTo)}
/>
<FormProvider
formID="moneyHoldReasonForm"
Expand Down

0 comments on commit fb43f88

Please sign in to comment.