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
20 changes: 15 additions & 5 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import enhanceParameters from '@libs/Network/enhanceParameters';
import {rand64} from '@libs/NumberUtils';
import {getActivePaymentType} from '@libs/PaymentUtils';
Expand Down Expand Up @@ -845,13 +846,22 @@ function rejectMoneyRequestsOnSearch(
if (isSingleReport && areAllExpensesSelected && !isPolicyDelayedSubmissionEnabled) {
const searchFullScreenRoutes = navigationRef.getRootState()?.routes.findLast((route) => route.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR);
const lastRoute = searchFullScreenRoutes?.state?.routes?.at(-1);
const focusedNavigator = navigationRef.getRootState()?.routes?.at(-1);
const isUserOnSearchPage = isSearchTopmostFullScreenRoute() && lastRoute?.name === SCREENS.SEARCH.ROOT;
const isUserOnSearchMoneyRequestReport = isSearchTopmostFullScreenRoute() && lastRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT;
const isUserOnSearchMoneyRequestReport =
focusedNavigator?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR &&
focusedNavigator?.state?.routes?.some((route) => route.name === SCREENS.RIGHT_MODAL.SEARCH_MONEY_REQUEST_REPORT);
if (isUserOnSearchPage) {
urlToNavigateBack = undefined;
} else if (isUserOnSearchMoneyRequestReport) {
const lastRouteParams = lastRoute?.params;
urlToNavigateBack = lastRouteParams && 'backTo' in lastRouteParams ? lastRouteParams?.backTo : undefined;
if (isUserOnSearchMoneyRequestReport && lastRoute?.params) {
const searchParams = lastRoute.params as SearchFullscreenNavigatorParamList[typeof SCREENS.SEARCH.ROOT];
urlToNavigateBack = ROUTES.SEARCH_ROOT.getRoute({
query: searchParams.q,
...(searchParams?.rawQuery && {rawQuery: searchParams.rawQuery}),
...(searchParams?.name && {name: searchParams.name}),
});
} else {
urlToNavigateBack = undefined;
}
Comment on lines +851 to +864
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up, lets try to look for ways to make this clearer, this feels very complex and we should at least add more comments @WojtekBoman

} else {
urlToNavigateBack = ROUTES.REPORT_WITH_ID.getRoute(report?.chatReportID);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/SearchRejectReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function SearchRejectReasonPage({route}: SearchRejectReasonPageProps) {
} else {
context.clearSelectedTransactions();
}
Navigation.dismissModal();
Navigation.dismissToSuperWideRHP();
if (urlToNavigateBack) {
Navigation.isNavigationReady().then(() => Navigation.goBack(urlToNavigateBack as Route));
}
Expand Down
11 changes: 9 additions & 2 deletions src/pages/iou/RejectReasonPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {getReportPolicyID} from '@selectors/Report';
import React, {useCallback, useEffect} from 'react';
import React, {useCallback, useContext, useEffect} from 'react';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import {useSearchContext} from '@components/Search/SearchContext';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
Expand Down Expand Up @@ -29,11 +30,17 @@ function RejectReasonPage({route}: RejectReasonPageProps) {
const {removeTransaction} = useSearchContext();
const [reportPolicyID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`, {canBeMissing: false, selector: getReportPolicyID});
const policy = usePolicy(reportPolicyID);
const {superWideRHPRouteKeys} = useContext(WideRHPContext);

const onSubmit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_REJECT_FORM>) => {
const urlToNavigateBack = rejectMoneyRequest(transactionID, reportID, values.comment, policy);
removeTransaction(transactionID);
Navigation.dismissToSuperWideRHP();
// If the super wide rhp is not opened, dismiss the entire modal.
if (superWideRHPRouteKeys.length > 0) {
Navigation.dismissToSuperWideRHP();
} else {
Navigation.dismissModal();
}
if (urlToNavigateBack && getIsSmallScreenWidth()) {
Navigation.isNavigationReady().then(() => Navigation.goBack(urlToNavigateBack));
}
Expand Down
Loading