From e96dc0849f20e5d696302b5665a6ea1d98a287f3 Mon Sep 17 00:00:00 2001
From: FitseTLT <engfitsum@gmail.com>
Date: Wed, 19 Nov 2025 17:33:28 +0300
Subject: [PATCH 1/4] made not found page navigations consistent

---
 .../workspace/WorkspacePageWithSections.tsx    | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx
index 940915787dbc..9e051290968c 100644
--- a/src/pages/workspace/WorkspacePageWithSections.tsx
+++ b/src/pages/workspace/WorkspacePageWithSections.tsx
@@ -17,9 +17,10 @@ import usePrevious from '@hooks/usePrevious';
 import useResponsiveLayout from '@hooks/useResponsiveLayout';
 import useThemeStyles from '@hooks/useThemeStyles';
 import {openWorkspaceView} from '@libs/actions/BankAccounts';
-import Navigation from '@libs/Navigation/Navigation';
-import {goBackFromInvalidPolicy, isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
+import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
+import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
 import CONST from '@src/CONST';
+import NAVIGATORS from '@src/NAVIGATORS';
 import ONYXKEYS from '@src/ONYXKEYS';
 import type {Route} from '@src/ROUTES';
 import ROUTES from '@src/ROUTES';
@@ -198,8 +199,17 @@ function WorkspacePageWithSections({
             shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow}
         >
             <FullPageNotFoundView
-                onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACES_LIST.route)}
-                onLinkPress={goBackFromInvalidPolicy}
+                onBackButtonPress={() => {
+                    const rootState = navigationRef.getRootState();
+                    const secondToLastRoute = rootState.routes.at(-2);
+
+                    if (secondToLastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) {
+                        Navigation.dismissModal();
+                    } else {
+                        Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
+                    }
+                }}
+                onLinkPress={() => Navigation.goBackToHome()}
                 shouldShow={shouldShow}
                 subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
                 shouldForceFullScreen

From 6a935e0c0b7bfaea9378153fef7cc643b6b88cac Mon Sep 17 00:00:00 2001
From: FitseTLT <engfitsum@gmail.com>
Date: Fri, 21 Nov 2025 16:06:37 +0300
Subject: [PATCH 2/4] minor typescript update

---
 src/pages/workspace/WorkspacePageWithSections.tsx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx
index 9e051290968c..f3c57715198c 100644
--- a/src/pages/workspace/WorkspacePageWithSections.tsx
+++ b/src/pages/workspace/WorkspacePageWithSections.tsx
@@ -18,6 +18,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
 import useThemeStyles from '@hooks/useThemeStyles';
 import {openWorkspaceView} from '@libs/actions/BankAccounts';
 import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
+import {RootNavigatorParamList, State} from '@libs/Navigation/types';
 import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
 import CONST from '@src/CONST';
 import NAVIGATORS from '@src/NAVIGATORS';
@@ -200,7 +201,7 @@ function WorkspacePageWithSections({
         >
             <FullPageNotFoundView
                 onBackButtonPress={() => {
-                    const rootState = navigationRef.getRootState();
+                    const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
                     const secondToLastRoute = rootState.routes.at(-2);
 
                     if (secondToLastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) {

From 6446615b8c73d6f8cb8c0a5961ae5960917e2c7a Mon Sep 17 00:00:00 2001
From: FitseTLT <engfitsum@gmail.com>
Date: Fri, 21 Nov 2025 16:10:44 +0300
Subject: [PATCH 3/4] fix type

---
 src/pages/workspace/WorkspacePageWithSections.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx
index f3c57715198c..7f3a0e070480 100644
--- a/src/pages/workspace/WorkspacePageWithSections.tsx
+++ b/src/pages/workspace/WorkspacePageWithSections.tsx
@@ -18,7 +18,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
 import useThemeStyles from '@hooks/useThemeStyles';
 import {openWorkspaceView} from '@libs/actions/BankAccounts';
 import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
-import {RootNavigatorParamList, State} from '@libs/Navigation/types';
+import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
 import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
 import CONST from '@src/CONST';
 import NAVIGATORS from '@src/NAVIGATORS';

From d077b2987e619b59d5306be95db9ab869509eb24 Mon Sep 17 00:00:00 2001
From: FitseTLT <engfitsum@gmail.com>
Date: Mon, 24 Nov 2025 21:42:58 +0300
Subject: [PATCH 4/4] refactor to a util function

---
 .../goBackFromWorkspaceSettingPages.ts        | 20 +++++++++++++++++++
 .../workspace/AccessOrNotFoundWrapper.tsx     | 14 +++----------
 .../workspace/WorkspacePageWithSections.tsx   | 17 +++-------------
 3 files changed, 26 insertions(+), 25 deletions(-)
 create mode 100644 src/libs/Navigation/helpers/goBackFromWorkspaceSettingPages.ts

diff --git a/src/libs/Navigation/helpers/goBackFromWorkspaceSettingPages.ts b/src/libs/Navigation/helpers/goBackFromWorkspaceSettingPages.ts
new file mode 100644
index 000000000000..963ffccb3a27
--- /dev/null
+++ b/src/libs/Navigation/helpers/goBackFromWorkspaceSettingPages.ts
@@ -0,0 +1,20 @@
+import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
+import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
+import NAVIGATORS from '@src/NAVIGATORS';
+import ROUTES from '@src/ROUTES';
+
+/**
+ * If the previous page is REPORTS_SPLIT_NAVIGATOR we navigate back to it
+ * otherwise we go back to WORKSPACES_LIST page.
+ */
+function goBackFromWorkspaceSettingPages() {
+    const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
+    const secondToLastRoute = rootState.routes.at(-2);
+
+    if (secondToLastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) {
+        Navigation.dismissModal();
+    } else {
+        Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
+    }
+}
+export default goBackFromWorkspaceSettingPages;
diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx
index 8639e4150e0b..2b79f330c54e 100644
--- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx
+++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx
@@ -12,14 +12,13 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
 import useResponsiveLayout from '@hooks/useResponsiveLayout';
 import {openWorkspace} from '@libs/actions/Policy/Policy';
 import {isValidMoneyRequestType} from '@libs/IOUUtils';
-import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
-import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
+import goBackFromWorkspaceSettingPages from '@libs/Navigation/helpers/goBackFromWorkspaceSettingPages';
+import Navigation from '@libs/Navigation/Navigation';
 import {canSendInvoice, isControlPolicy, isPaidGroupPolicy, isPolicyAccessible, isPolicyAdmin, isPolicyFeatureEnabled as isPolicyFeatureEnabledUtil} from '@libs/PolicyUtils';
 import {canCreateRequest} from '@libs/ReportUtils';
 import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
 import type {IOUType} from '@src/CONST';
 import CONST from '@src/CONST';
-import NAVIGATORS from '@src/NAVIGATORS';
 import ONYXKEYS from '@src/ONYXKEYS';
 import ROUTES from '@src/ROUTES';
 import SCREENS from '@src/SCREENS';
@@ -117,14 +116,7 @@ function PageNotFoundFallback({policyID, fullPageNotFoundViewProps, isFeatureEna
             shouldShowOfflineIndicator={false}
             onBackButtonPress={() => {
                 if (isPolicyNotAccessible) {
-                    const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
-                    const secondToLastRoute = rootState.routes.at(-2);
-
-                    if (secondToLastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) {
-                        Navigation.dismissModal();
-                    } else {
-                        Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
-                    }
+                    goBackFromWorkspaceSettingPages();
                     return;
                 }
                 Navigation.goBack(policyID && !isMoneyRequest ? ROUTES.WORKSPACE_OVERVIEW.getRoute(policyID) : undefined);
diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx
index 7f3a0e070480..7e51119cecf9 100644
--- a/src/pages/workspace/WorkspacePageWithSections.tsx
+++ b/src/pages/workspace/WorkspacePageWithSections.tsx
@@ -17,14 +17,12 @@ import usePrevious from '@hooks/usePrevious';
 import useResponsiveLayout from '@hooks/useResponsiveLayout';
 import useThemeStyles from '@hooks/useThemeStyles';
 import {openWorkspaceView} from '@libs/actions/BankAccounts';
-import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
-import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
+import goBackFromWorkspaceSettingPages from '@libs/Navigation/helpers/goBackFromWorkspaceSettingPages';
+import Navigation from '@libs/Navigation/Navigation';
 import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
 import CONST from '@src/CONST';
-import NAVIGATORS from '@src/NAVIGATORS';
 import ONYXKEYS from '@src/ONYXKEYS';
 import type {Route} from '@src/ROUTES';
-import ROUTES from '@src/ROUTES';
 import type {Policy} from '@src/types/onyx';
 import {isEmptyObject} from '@src/types/utils/EmptyObject';
 import type IconAsset from '@src/types/utils/IconAsset';
@@ -200,16 +198,7 @@ function WorkspacePageWithSections({
             shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow}
         >
             <FullPageNotFoundView
-                onBackButtonPress={() => {
-                    const rootState = navigationRef.getRootState() as State<RootNavigatorParamList>;
-                    const secondToLastRoute = rootState.routes.at(-2);
-
-                    if (secondToLastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) {
-                        Navigation.dismissModal();
-                    } else {
-                        Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
-                    }
-                }}
+                onBackButtonPress={goBackFromWorkspaceSettingPages}
                 onLinkPress={() => Navigation.goBackToHome()}
                 shouldShow={shouldShow}
                 subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined}
