From fd565099539f3403873456646955bf50507768f6 Mon Sep 17 00:00:00 2001
From: Maxence Coulibaly <maxence@expensify.com>
Date: Fri, 26 Jul 2024 16:15:55 +0000
Subject: [PATCH 1/9] Merge pull request #45730 from allroundexperts/fix-45689

fix: redirect to proper place after upgrade
---
 .../ConnectToNetSuiteButton/index.tsx         |  4 +++-
 .../ConnectToSageIntacctButton/index.tsx      |  8 +++++++-
 .../categories/CategorySettingsPage.tsx       | 16 ++++++++++++++--
 src/pages/workspace/tags/TagSettingsPage.tsx  |  8 +++++++-
 .../workspace/upgrade/UpgradeConfirmation.tsx |  6 +++---
 .../upgrade/WorkspaceUpgradePage.tsx          | 19 +++++++++++++++----
 src/styles/index.ts                           |  7 +------
 7 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/src/components/ConnectToNetSuiteButton/index.tsx b/src/components/ConnectToNetSuiteButton/index.tsx
index 928bc01f12c1..bd6dabf09097 100644
--- a/src/components/ConnectToNetSuiteButton/index.tsx
+++ b/src/components/ConnectToNetSuiteButton/index.tsx
@@ -56,7 +56,9 @@ function ConnectToNetSuiteButton({policyID, shouldDisconnectIntegrationBeforeCon
             <Button
                 onPress={() => {
                     if (!isControlPolicy(policy)) {
-                        Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias));
+                        Navigation.navigate(
+                            ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID)),
+                        );
                         return;
                     }
 
diff --git a/src/components/ConnectToSageIntacctButton/index.tsx b/src/components/ConnectToSageIntacctButton/index.tsx
index 6c6523ad6e75..1286e3b8fc59 100644
--- a/src/components/ConnectToSageIntacctButton/index.tsx
+++ b/src/components/ConnectToSageIntacctButton/index.tsx
@@ -63,7 +63,13 @@ function ConnectToSageIntacctButton({policyID, shouldDisconnectIntegrationBefore
             <Button
                 onPress={() => {
                     if (!isControlPolicy(policy)) {
-                        Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias));
+                        Navigation.navigate(
+                            ROUTES.WORKSPACE_UPGRADE.getRoute(
+                                policyID,
+                                CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias,
+                                ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID),
+                            ),
+                        );
                         return;
                     }
 
diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx
index d1d605759d36..83a1bfd53aca 100644
--- a/src/pages/workspace/categories/CategorySettingsPage.tsx
+++ b/src/pages/workspace/categories/CategorySettingsPage.tsx
@@ -141,7 +141,13 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet
                             description={translate(`workspace.categories.glCode`)}
                             onPress={() => {
                                 if (!isControlPolicy(policy)) {
-                                    Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias));
+                                    Navigation.navigate(
+                                        ROUTES.WORKSPACE_UPGRADE.getRoute(
+                                            route.params.policyID,
+                                            CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias,
+                                            ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(route.params.policyID, policyCategory.name),
+                                        ),
+                                    );
                                     return;
                                 }
                                 Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(route.params.policyID, policyCategory.name));
@@ -155,7 +161,13 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet
                             description={translate(`workspace.categories.payrollCode`)}
                             onPress={() => {
                                 if (!isControlPolicy(policy)) {
-                                    Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias));
+                                    Navigation.navigate(
+                                        ROUTES.WORKSPACE_UPGRADE.getRoute(
+                                            route.params.policyID,
+                                            CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias,
+                                            ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(route.params.policyID, policyCategory.name),
+                                        ),
+                                    );
                                     return;
                                 }
                                 Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(route.params.policyID, policyCategory.name));
diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx
index 2a03c7c8a275..3ddc5b2ab3cb 100644
--- a/src/pages/workspace/tags/TagSettingsPage.tsx
+++ b/src/pages/workspace/tags/TagSettingsPage.tsx
@@ -72,7 +72,13 @@ function TagSettingsPage({route, policyTags, navigation}: TagSettingsPageProps)
 
     const navigateToEditGlCode = () => {
         if (!PolicyUtils.isControlPolicy(policy)) {
-            Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(route.params.policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias));
+            Navigation.navigate(
+                ROUTES.WORKSPACE_UPGRADE.getRoute(
+                    route.params.policyID,
+                    CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias,
+                    ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policy?.id ?? '', route.params.orderWeight, route.params.tagName),
+                ),
+            );
             return;
         }
         Navigation.navigate(ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(route.params.policyID, route.params.orderWeight, currentPolicyTag.name));
diff --git a/src/pages/workspace/upgrade/UpgradeConfirmation.tsx b/src/pages/workspace/upgrade/UpgradeConfirmation.tsx
index c0ad11e1f74a..6ad6b6300667 100644
--- a/src/pages/workspace/upgrade/UpgradeConfirmation.tsx
+++ b/src/pages/workspace/upgrade/UpgradeConfirmation.tsx
@@ -8,10 +8,10 @@ import ROUTES from '@src/ROUTES';
 
 type Props = {
     policyName: string;
-    policyID: string;
+    onConfirmUpgrade: () => void;
 };
 
-function UpgradeConfirmation({policyName, policyID}: Props) {
+function UpgradeConfirmation({policyName, onConfirmUpgrade}: Props) {
     const {translate} = useLocalize();
     const styles = useThemeStyles();
 
@@ -31,7 +31,7 @@ function UpgradeConfirmation({policyName, policyID}: Props) {
                 </>
             }
             shouldShowButton
-            onButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_PROFILE.getRoute(policyID))}
+            onButtonPress={onConfirmUpgrade}
             buttonText={translate('workspace.upgrade.completed.gotIt')}
         />
     );
diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
index 69eb396e9e26..c0041bddb1b5 100644
--- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
+++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
@@ -8,6 +8,7 @@ import useNetwork from '@hooks/useNetwork';
 import useThemeStyles from '@hooks/useThemeStyles';
 import Navigation from '@libs/Navigation/Navigation';
 import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
+import {isControlPolicy} from '@libs/PolicyUtils';
 import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
 import CONST from '@src/CONST';
 import * as Policy from '@src/libs/actions/Policy/Policy';
@@ -26,15 +27,25 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
     const [policy] = useOnyx(`policy_${policyID}`);
     const {isOffline} = useNetwork();
 
+    const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]);
+
     if (!feature || !policy) {
         return <NotFoundPage />;
     }
 
     const upgradeToCorporate = () => {
-        Policy.upgradeToCorporate(policy.id, feature.id);
+        Policy.upgradeToCorporate(policy.id, feature.name);
     };
 
-    const isUpgraded = policy.type === CONST.POLICY.TYPE.CORPORATE;
+    const confirmUpgrade = () => {
+        switch (feature.id) {
+            case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id:
+                Policy.enablePolicyReportFields(policyID, true);
+                return Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID), CONST.NAVIGATION.TYPE.UP);
+            default:
+                return route.params.backTo ? Navigation.navigate(route.params.backTo, CONST.NAVIGATION.TYPE.UP) : Navigation.goBack();
+        }
+    };
 
     return (
         <ScreenWrapper
@@ -44,11 +55,11 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
         >
             <HeaderWithBackButton
                 title={translate('common.upgrade')}
-                onBackButtonPress={() => Navigation.goBack(route.params.backTo ?? ROUTES.WORKSPACE_PROFILE.getRoute(policyID))}
+                onBackButtonPress={() => Navigation.goBack()}
             />
             {isUpgraded && (
                 <UpgradeConfirmation
-                    policyID={policy.id}
+                    onConfirmUpgrade={confirmUpgrade}
                     policyName={policy.name}
                 />
             )}
diff --git a/src/styles/index.ts b/src/styles/index.ts
index b3cb5b624bac..5e85d95e92b0 100644
--- a/src/styles/index.ts
+++ b/src/styles/index.ts
@@ -2735,15 +2735,10 @@ const styles = (theme: ThemeColors) =>
             width: 110,
         },
 
-        workspaceUpgradeIntroBox: ({isExtraSmallScreenWidth, isSmallScreenWidth}: WorkspaceUpgradeIntroBoxParams): ViewStyle => {
+        workspaceUpgradeIntroBox: ({isExtraSmallScreenWidth}: WorkspaceUpgradeIntroBoxParams): ViewStyle => {
             let paddingHorizontal = spacing.ph5;
             let paddingVertical = spacing.pv5;
 
-            if (isSmallScreenWidth) {
-                paddingHorizontal = spacing.ph4;
-                paddingVertical = spacing.pv4;
-            }
-
             if (isExtraSmallScreenWidth) {
                 paddingHorizontal = spacing.ph2;
                 paddingVertical = spacing.pv2;

From 6c2712d960563cd11117a0bf6aa6cca564c99c09 Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Thu, 1 Aug 2024 03:09:05 +0500
Subject: [PATCH 2/9] fix back navigation

---
 src/libs/actions/Policy/Policy.ts                          | 4 ++--
 src/pages/workspace/categories/CategoryGLCodePage.tsx      | 2 +-
 src/pages/workspace/categories/CategoryPayrollCodePage.tsx | 2 +-
 src/pages/workspace/tags/TagGLCodePage.tsx                 | 2 +-
 src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx       | 6 +++---
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts
index 1bce525e22bf..6db94184dae9 100644
--- a/src/libs/actions/Policy/Policy.ts
+++ b/src/libs/actions/Policy/Policy.ts
@@ -2607,7 +2607,7 @@ function enableExpensifyCard(policyID: string, enabled: boolean) {
     }
 }
 
-function enablePolicyReportFields(policyID: string, enabled: boolean) {
+function enablePolicyReportFields(policyID: string, enabled: boolean, disableRedirect = false) {
     const onyxData: OnyxData = {
         optimisticData: [
             {
@@ -2650,7 +2650,7 @@ function enablePolicyReportFields(policyID: string, enabled: boolean) {
 
     API.write(WRITE_COMMANDS.ENABLE_POLICY_REPORT_FIELDS, parameters, onyxData);
 
-    if (enabled && getIsNarrowLayout()) {
+    if (enabled && getIsNarrowLayout() && !disableRedirect) {
         navigateWhenEnableFeature(policyID);
     }
 }
diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx
index 2a56184b7ba8..12660597247f 100644
--- a/src/pages/workspace/categories/CategoryGLCodePage.tsx
+++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx
@@ -38,7 +38,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) {
             if (newGLCode !== glCode) {
                 Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode);
             }
-            Navigation.goBack();
+            Navigation.dismissModal();
         },
         [categoryName, glCode, route.params.policyID],
     );
diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
index 22143add373a..b387aaca7bd5 100644
--- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
+++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
@@ -38,7 +38,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) {
             if (newPayrollCode !== payrollCode) {
                 Category.setPolicyCategoryPayrollCode(route.params.policyID, categoryName, newPayrollCode);
             }
-            Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName));
+            Navigation.dismissModal();
         },
         [categoryName, payrollCode, route.params.categoryName, route.params.policyID],
     );
diff --git a/src/pages/workspace/tags/TagGLCodePage.tsx b/src/pages/workspace/tags/TagGLCodePage.tsx
index 5276e7e3b2d7..38d5fabca1ee 100644
--- a/src/pages/workspace/tags/TagGLCodePage.tsx
+++ b/src/pages/workspace/tags/TagGLCodePage.tsx
@@ -45,7 +45,7 @@ function TagGLCodePage({route, policyTags}: EditTagGLCodePageProps) {
             if (newGLCode !== glCode) {
                 Tag.setPolicyTagGLCode(route.params.policyID, tagName, orderWeight, newGLCode);
             }
-            Navigation.goBack();
+            Navigation.dismissModal();
         },
         [glCode, route.params.policyID, tagName, orderWeight],
     );
diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
index c0041bddb1b5..d1ab3d1d27d9 100644
--- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
+++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
@@ -40,10 +40,10 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
     const confirmUpgrade = () => {
         switch (feature.id) {
             case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id:
-                Policy.enablePolicyReportFields(policyID, true);
-                return Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID), CONST.NAVIGATION.TYPE.UP);
+                Policy.enablePolicyReportFields(policyID, true, true);
+                return Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID));
             default:
-                return route.params.backTo ? Navigation.navigate(route.params.backTo, CONST.NAVIGATION.TYPE.UP) : Navigation.goBack();
+                return route.params.backTo ? Navigation.navigate(route.params.backTo) : Navigation.goBack();
         }
     };
 

From 7278e03c6bc4cf23b8a2d2043f5712cd8ecbbd5d Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Thu, 1 Aug 2024 03:34:02 +0500
Subject: [PATCH 3/9] fix: lint errors

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

diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
index b387aaca7bd5..a72e4238d91b 100644
--- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
+++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx
@@ -40,7 +40,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) {
             }
             Navigation.dismissModal();
         },
-        [categoryName, payrollCode, route.params.categoryName, route.params.policyID],
+        [categoryName, payrollCode, route.params.policyID],
     );
 
     return (

From 73dd174b3f42acae346f25c43e6e1f1173df7886 Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Thu, 1 Aug 2024 22:28:22 +0500
Subject: [PATCH 4/9] change size of illustrations to 48px

---
 src/pages/workspace/upgrade/UpgradeIntro.tsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/pages/workspace/upgrade/UpgradeIntro.tsx b/src/pages/workspace/upgrade/UpgradeIntro.tsx
index 3089e0244184..7739d874175a 100644
--- a/src/pages/workspace/upgrade/UpgradeIntro.tsx
+++ b/src/pages/workspace/upgrade/UpgradeIntro.tsx
@@ -1,9 +1,9 @@
 import React from 'react';
 import {View} from 'react-native';
 import type {ValueOf} from 'type-fest';
-import Avatar from '@components/Avatar';
 import Badge from '@components/Badge';
 import Button from '@components/Button';
+import Icon from '@components/Icon';
 import * as Expensicon from '@components/Icon/Expensicons';
 import * as Illustrations from '@components/Icon/Illustrations';
 import Text from '@components/Text';
@@ -32,9 +32,10 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading}: Props) {
         <View style={styles.p5}>
             <View style={styles.workspaceUpgradeIntroBox({isExtraSmallScreenWidth, isSmallScreenWidth})}>
                 <View style={[styles.mb3, styles.flexRow, styles.justifyContentBetween]}>
-                    <Avatar
-                        type={CONST.ICON_TYPE_AVATAR}
-                        source={iconSrc}
+                    <Icon
+                        src={iconSrc}
+                        width={48}
+                        height={48}
                     />
                     <Badge
                         icon={Expensicon.Unlock}

From 409a1f25455143606a3e5e8d7202eb0f231c69cc Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Thu, 1 Aug 2024 22:42:40 +0500
Subject: [PATCH 5/9] do not change icon size

---
 src/pages/workspace/upgrade/UpgradeIntro.tsx | 21 ++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/pages/workspace/upgrade/UpgradeIntro.tsx b/src/pages/workspace/upgrade/UpgradeIntro.tsx
index 7739d874175a..2b1140470703 100644
--- a/src/pages/workspace/upgrade/UpgradeIntro.tsx
+++ b/src/pages/workspace/upgrade/UpgradeIntro.tsx
@@ -1,6 +1,7 @@
 import React from 'react';
 import {View} from 'react-native';
 import type {ValueOf} from 'type-fest';
+import Avatar from '@components/Avatar';
 import Badge from '@components/Badge';
 import Button from '@components/Button';
 import Icon from '@components/Icon';
@@ -26,17 +27,25 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading}: Props) {
     const styles = useThemeStyles();
     const {isExtraSmallScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
     const {translate} = useLocalize();
-    const iconSrc = feature.icon in Illustrations ? Illustrations[feature.icon as keyof typeof Illustrations] : Expensicon[feature.icon as keyof typeof Expensicon];
+    const isIllustration = feature.icon in Illustrations;
+    const iconSrc = isIllustration ? Illustrations[feature.icon as keyof typeof Illustrations] : Expensicon[feature.icon as keyof typeof Expensicon];
 
     return (
         <View style={styles.p5}>
             <View style={styles.workspaceUpgradeIntroBox({isExtraSmallScreenWidth, isSmallScreenWidth})}>
                 <View style={[styles.mb3, styles.flexRow, styles.justifyContentBetween]}>
-                    <Icon
-                        src={iconSrc}
-                        width={48}
-                        height={48}
-                    />
+                    {!isIllustration ? (
+                        <Avatar
+                            source={iconSrc}
+                            type={CONST.ICON_TYPE_AVATAR}
+                        />
+                    ) : (
+                        <Icon
+                            src={iconSrc}
+                            width={48}
+                            height={48}
+                        />
+                    )}
                     <Badge
                         icon={Expensicon.Unlock}
                         text={translate('workspace.upgrade.upgradeToUnlock')}

From 30374075b3b5b8518399fdeb5c25c9b260d3fb5a Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Wed, 7 Aug 2024 01:50:15 +0500
Subject: [PATCH 6/9] back button fix

---
 src/libs/Permissions.ts                              | 2 +-
 src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts
index a7348e143e60..cd4f4afb3d3b 100644
--- a/src/libs/Permissions.ts
+++ b/src/libs/Permissions.ts
@@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST';
 import type Beta from '@src/types/onyx/Beta';
 
 function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
-    return !!betas?.includes(CONST.BETAS.ALL);
+    return true; // !!betas?.includes(CONST.BETAS.ALL);
 }
 
 function canUseDefaultRooms(betas: OnyxEntry<Beta[]>): boolean {
diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
index d1ab3d1d27d9..4b8a142805a2 100644
--- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
+++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
@@ -55,7 +55,7 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
         >
             <HeaderWithBackButton
                 title={translate('common.upgrade')}
-                onBackButtonPress={() => Navigation.goBack()}
+                onBackButtonPress={() => (isUpgraded ? confirmUpgrade() : Navigation.goBack())}
             />
             {isUpgraded && (
                 <UpgradeConfirmation

From 612f6d116d67f7615c8d4d5bf7cc073de3ac1a89 Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Wed, 7 Aug 2024 01:50:41 +0500
Subject: [PATCH 7/9] undo use all betas

---
 src/libs/Permissions.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts
index cd4f4afb3d3b..a7348e143e60 100644
--- a/src/libs/Permissions.ts
+++ b/src/libs/Permissions.ts
@@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST';
 import type Beta from '@src/types/onyx/Beta';
 
 function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
-    return true; // !!betas?.includes(CONST.BETAS.ALL);
+    return !!betas?.includes(CONST.BETAS.ALL);
 }
 
 function canUseDefaultRooms(betas: OnyxEntry<Beta[]>): boolean {

From 9fecc9db6b97fa6d78003a14a7a90b8a5c33df0a Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Wed, 7 Aug 2024 02:59:25 +0500
Subject: [PATCH 8/9] improve logic

---
 .../upgrade/WorkspaceUpgradePage.tsx          | 38 ++++++++++++++-----
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
index 4b8a142805a2..0837ac164600 100644
--- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
+++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
@@ -1,5 +1,6 @@
+import {useNavigation} from '@react-navigation/native';
 import type {StackScreenProps} from '@react-navigation/stack';
-import React from 'react';
+import React, {useCallback, useEffect} from 'react';
 import {useOnyx} from 'react-native-onyx';
 import HeaderWithBackButton from '@components/HeaderWithBackButton';
 import ScreenWrapper from '@components/ScreenWrapper';
@@ -20,6 +21,7 @@ import UpgradeIntro from './UpgradeIntro';
 type WorkspaceUpgradePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.UPGRADE>;
 
 function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
+    const navigation = useNavigation();
     const styles = useThemeStyles();
     const policyID = route.params.policyID;
     const feature = Object.values(CONST.UPGRADE_FEATURE_INTRO_MAPPING).find((f) => f.alias === route.params.featureName);
@@ -29,15 +31,18 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
 
     const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]);
 
-    if (!feature || !policy) {
-        return <NotFoundPage />;
-    }
-
     const upgradeToCorporate = () => {
+        if (!policy || !feature) {
+            return;
+        }
+
         Policy.upgradeToCorporate(policy.id, feature.name);
     };
 
-    const confirmUpgrade = () => {
+    const confirmUpgrade = useCallback(() => {
+        if (!feature) {
+            return;
+        }
         switch (feature.id) {
             case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id:
                 Policy.enablePolicyReportFields(policyID, true, true);
@@ -45,7 +50,22 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
             default:
                 return route.params.backTo ? Navigation.navigate(route.params.backTo) : Navigation.goBack();
         }
-    };
+    }, [feature, policyID, route.params.backTo]);
+
+    useEffect(() => {
+        const unsubscribeListener = navigation.addListener('blur', () => {
+            if (!isUpgraded) {
+                return;
+            }
+            confirmUpgrade();
+        });
+
+        return unsubscribeListener;
+    }, [isUpgraded, confirmUpgrade, navigation]);
+
+    if (!feature || !policy) {
+        return <NotFoundPage />;
+    }
 
     return (
         <ScreenWrapper
@@ -55,11 +75,11 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) {
         >
             <HeaderWithBackButton
                 title={translate('common.upgrade')}
-                onBackButtonPress={() => (isUpgraded ? confirmUpgrade() : Navigation.goBack())}
+                onBackButtonPress={() => (isUpgraded ? Navigation.dismissModal() : Navigation.goBack())}
             />
             {isUpgraded && (
                 <UpgradeConfirmation
-                    onConfirmUpgrade={confirmUpgrade}
+                    onConfirmUpgrade={() => Navigation.dismissModal()}
                     policyName={policy.name}
                 />
             )}

From 97dbd8b2382c9a35a84e8e4ad1408d955979d0ed Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Thu, 8 Aug 2024 00:36:53 +0500
Subject: [PATCH 9/9] resolve conflicts

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

diff --git a/src/pages/workspace/upgrade/UpgradeIntro.tsx b/src/pages/workspace/upgrade/UpgradeIntro.tsx
index efba70a370a9..5fe04fb7a0ce 100644
--- a/src/pages/workspace/upgrade/UpgradeIntro.tsx
+++ b/src/pages/workspace/upgrade/UpgradeIntro.tsx
@@ -45,7 +45,7 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading}: Props) {
                             src={iconSrc}
                             width={48}
                             height={48}
-                            iconAdditionalStyles={iconAdditionalStyles}
+                            additionalStyles={iconAdditionalStyles}
                         />
                     )}
                     <Badge
