Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/MoneyRequestAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {createTransactionThreadReport} from '@libs/actions/Report';
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -124,7 +125,7 @@ function MoneyRequestAction({
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo: Navigation.getActiveRoute()}));
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(transactionThreadReport?.reportID, undefined, undefined, Navigation.getActiveRoute()));
Navigation.navigate(getReportRouteForCurrentContext({reportID: transactionThreadReport?.reportID}));
return;
}

Expand All @@ -133,7 +134,7 @@ function MoneyRequestAction({
return;
}

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(action?.childReportID, undefined, undefined, Navigation.getActiveRoute()));
Navigation.navigate(getReportRouteForCurrentContext({reportID: action?.childReportID}));
};

const isDeletedParentAction = isDeletedParentActionReportActionsUtils(action);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import {canActionTask, completeTask, getTaskAssigneeAccountID, reopenTask} from
import ControlSelection from '@libs/ControlSelection';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import getButtonState from '@libs/getButtonState';
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import {isCanceledTaskReport, isOpenTaskReport, isReportManager} from '@libs/ReportUtils';
import type {ContextMenuAnchor} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report, ReportAction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand Down Expand Up @@ -142,7 +142,7 @@ function TaskPreview({
return (
<View style={[styles.chatItemMessage, !hasAssignee && styles.mv1]}>
<PressableWithoutFeedback
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(taskReportID, undefined, undefined, Navigation.getActiveRoute()))}
onPress={() => Navigation.navigate(getReportRouteForCurrentContext({reportID: taskReportID}))}
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) =>
Expand Down
18 changes: 18 additions & 0 deletions src/libs/Navigation/helpers/dismissModalForCurrentContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Navigation from '@libs/Navigation/Navigation';
import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute';

function dismissModalForCurrentContext(reportID?: string) {
if (isSearchTopmostFullScreenRoute()) {
Navigation.dismissModal();
return;
}

if (!reportID) {
Navigation.dismissModal();
return;
}

Navigation.dismissModalWithReport({reportID});
}

export default dismissModalForCurrentContext;
22 changes: 22 additions & 0 deletions src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute';

type GetReportRouteForCurrentContextParams = {
reportID: string | undefined;
reportActionID?: string;
backTo?: Route;
};

function getReportRouteForCurrentContext({reportID, reportActionID, backTo}: GetReportRouteForCurrentContextParams): Route {
const currentRoute = backTo ?? (Navigation.getActiveRoute() as Route);

if (isSearchTopmostFullScreenRoute()) {
return ROUTES.SEARCH_REPORT.getRoute({reportID, reportActionID, backTo: currentRoute});
}

return ROUTES.REPORT_WITH_ID.getRoute(reportID, reportActionID, undefined, currentRoute);
}

export default getReportRouteForCurrentContext;
35 changes: 35 additions & 0 deletions src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';

function normalizeRoute(route: string): string {
return route
.replaceAll(/\?.*/g, '')
.replaceAll(/^\/+|\/+$/g, '')
.replaceAll(/\/+/g, '/');
}

function doesRouteTargetCurrentReport(route: string, reportID: string): boolean {
const normalizedRoute = normalizeRoute(route);
const currentReportRoutes = [
ROUTES.REPORT_WITH_ID.getRoute(reportID),
ROUTES.SEARCH_REPORT.getRoute({reportID}),
ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}),
ROUTES.EXPENSE_REPORT_RHP.getRoute({reportID}),
].map(normalizeRoute);

return currentReportRoutes.some((currentReportRoute) => normalizedRoute === currentReportRoute || normalizedRoute.startsWith(`${currentReportRoute}/`));
}

function shouldUseBackToOnLeaveReport(reportID: string | undefined, backTo?: Route): boolean {
if (!backTo) {
return false;
}

if (!reportID) {
return true;
}

return !doesRouteTargetCurrentReport(backTo, reportID);
}

export default shouldUseBackToOnLeaveReport;
17 changes: 14 additions & 3 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
import Log from '@libs/Log';
import {isEmailPublicDomain} from '@libs/LoginUtils';
import {getMovedReportID} from '@libs/ModifiedExpenseMessage';
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import type {LinkToOptions} from '@libs/Navigation/helpers/linkTo/types';
import shouldUseBackToOnLeaveReport from '@libs/Navigation/helpers/shouldUseBackToOnLeaveReport';
import Navigation from '@libs/Navigation/Navigation';
import enhanceParameters from '@libs/Network/enhanceParameters';
import * as NetworkStore from '@libs/Network/NetworkStore';
Expand Down Expand Up @@ -195,6 +197,7 @@
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/NewRoomForm';
import type {
AnyRequest,
Expand Down Expand Up @@ -381,7 +384,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 387 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -393,7 +396,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 399 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -402,7 +405,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 408 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -417,7 +420,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 423 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand Down Expand Up @@ -2073,7 +2076,7 @@
) {
const report = childReport ?? createChildReport(childReport, parentReportAction, parentReport, currentUserAccountID, introSelected, betas);

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID, undefined, undefined, Navigation.getActiveRoute()));
Navigation.navigate(getReportRouteForCurrentContext({reportID: report.reportID}));
}

/**
Expand Down Expand Up @@ -4297,7 +4300,13 @@
currentUserAccountID: number,
introSelected: OnyxEntry<IntroSelected>,
betas: OnyxEntry<Beta[]>,
backTo?: Route,
) {
if (shouldUseBackToOnLeaveReport(currentReport?.reportID, backTo)) {
Navigation.goBack(backTo);
return;
}

const lastAccessedReportID = findLastAccessedReport(false, false, currentReport?.reportID)?.reportID;

if (lastAccessedReportID) {
Expand Down Expand Up @@ -4349,6 +4358,7 @@
conciergeReportID: string | undefined,
introSelected: OnyxEntry<IntroSelected>,
betas: OnyxEntry<Beta[]>,
backTo?: Route,
) {
const reportID = report.reportID;
// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
Expand Down Expand Up @@ -4396,7 +4406,7 @@
},
];

navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas);
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas, backTo);
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData});
}

Expand All @@ -4408,6 +4418,7 @@
introSelected: OnyxEntry<IntroSelected>,
betas: OnyxEntry<Beta[]>,
isWorkspaceMemberLeavingWorkspaceRoom = false,
backTo?: Route,
) {
const reportID = report.reportID;
const isChatThread = isChatThreadReportUtils(report);
Expand Down Expand Up @@ -4512,7 +4523,7 @@
return;
}
// In other cases, the report is deleted and we should move the user to another report.
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas);
navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas, backTo);
}

function buildInviteToRoomOnyxData(report: Report, inviteeEmailsToAccountIDs: InvitedEmailsToAccountIDs, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']) {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import NetworkConnection from '@libs/NetworkConnection';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -375,7 +376,7 @@ function createTaskAndNavigate(params: CreateTaskAndNavigateParams) {
InteractionManager.runAfterInteractions(() => {
clearOutTaskInfo();
});
Navigation.dismissModalWithReport({reportID: parentReportID});
dismissModalForCurrentContext(parentReportID);
}
notifyNewAction(parentReportID, optimisticAddCommentReport.reportAction, true);
}
Expand Down
7 changes: 4 additions & 3 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail

const leaveChat = useCallback(() => {
if (isRootGroupChat) {
leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas);
leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, backTo);
return;
}

const isWorkspaceMemberLeavingWorkspaceRoom = isWorkspaceMemberLeavingWorkspaceRoomUtil(report, isPolicyEmployee, isPolicyAdmin);
leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, isWorkspaceMemberLeavingWorkspaceRoom);
}, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas]);
leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, isWorkspaceMemberLeavingWorkspaceRoom, backTo);
}, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, backTo]);

const showLastMemberLeavingModal = useCallback(async () => {
const {action} = await showConfirmModal({
Expand Down Expand Up @@ -634,6 +634,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
iouTransactionID,
moneyRequestReport?.reportID,
currentUserPersonalDetails.accountID,
currentUserPersonalDetails.email,
isTaskActionable,
isRootGroupChat,
leaveChat,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/inbox/ReportNavigateAwayHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useParentReportAction from '@hooks/useParentReportAction';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import {isDeletedParentAction} from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -204,6 +205,10 @@ function ReportNavigateAwayHandler() {

// Fallback to Concierge
Navigation.isNavigationReady().then(() => {
if (isSearchTopmostFullScreenRoute()) {
Navigation.dismissModal();
return;
}
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas);
});
}, [reportWasDeleted, isFocused, deletedReportParentID, conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas]);
Expand Down
5 changes: 3 additions & 2 deletions src/pages/tasks/TaskAssigneeSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {searchUserInServer} from '@libs/actions/Report';
import {canModifyTask, editTaskAssignee, setAssigneeValue} from '@libs/actions/Task';
import {READ_COMMANDS} from '@libs/API/types';
import HttpUtils from '@libs/HttpUtils';
import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import {getHeaderMessage, isCurrentUser} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -88,7 +89,7 @@ function TaskAssigneeSelectorModal() {
const reportOnyx = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`];
if (reportOnyx && !isTaskReport(reportOnyx)) {
Navigation.isNavigationReady().then(() => {
Navigation.dismissModalWithReport({reportID: reportOnyx.reportID});
dismissModalForCurrentContext(reportOnyx.reportID);
});
}
return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`];
Expand Down Expand Up @@ -184,7 +185,7 @@ function TaskAssigneeSelectorModal() {
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
Navigation.dismissModalWithReport({reportID: report?.reportID});
dismissModalForCurrentContext(report?.reportID);
});
// If there's no report, we're creating a new task
} else if (option.accountID) {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/tasks/TaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import {addErrorMessage} from '@libs/ErrorUtils';
import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportDescriptionNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -62,14 +63,14 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti
editTask(report, {description: values.description}, delegateEmail);
}

Navigation.dismissModalWithReport({reportID: report?.reportID});
dismissModalForCurrentContext(report?.reportID);
},
[report, delegateEmail],
);

if (!isTaskReport(report)) {
Navigation.isNavigationReady().then(() => {
Navigation.dismissModalWithReport({reportID: report?.reportID});
dismissModalForCurrentContext(report?.reportID);
});
}
const inputRef = useRef<AnimatedTextInputRef | null>(null);
Expand Down
5 changes: 3 additions & 2 deletions src/pages/tasks/TaskTitlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import {addErrorMessage} from '@libs/ErrorUtils';
import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {TaskDetailsNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -67,14 +68,14 @@ function TaskTitlePage({report, currentUserPersonalDetails}: TaskTitlePageProps)
editTask(report, {title: values.title}, delegateEmail);
}

Navigation.dismissModalWithReport({reportID: report?.reportID});
dismissModalForCurrentContext(report?.reportID);
},
[report, delegateEmail],
);

if (!isTaskReport(report)) {
Navigation.isNavigationReady().then(() => {
Navigation.dismissModalWithReport({reportID: report?.reportID});
dismissModalForCurrentContext(report?.reportID);
});
}

Expand Down
Loading