From 838894668324db508f780a4fbcdf84b9573a2db9 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 15 Mar 2024 05:15:34 +0530 Subject: [PATCH 1/2] switch to all workspace view when workspace is deleted --- src/pages/workspace/WorkspaceProfilePage.tsx | 12 +++++++++--- src/pages/workspace/WorkspacesListPage.tsx | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/WorkspaceProfilePage.tsx b/src/pages/workspace/WorkspaceProfilePage.tsx index 2df6dd0489f9..59c66f0c06a7 100644 --- a/src/pages/workspace/WorkspaceProfilePage.tsx +++ b/src/pages/workspace/WorkspaceProfilePage.tsx @@ -14,6 +14,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; import Text from '@components/Text'; +import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useLocalize from '@hooks/useLocalize'; import useThemeIllustrations from '@hooks/useThemeIllustrations'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -45,6 +46,7 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); const illustrations = useThemeIllustrations(); + const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace(); const outputCurrency = policy?.outputCurrency ?? ''; const currencySymbol = currencyList?.[outputCurrency]?.symbol ?? ''; @@ -84,11 +86,15 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi } Policy.deleteWorkspace(policy?.id, policyName); - PolicyUtils.goBackFromInvalidPolicy(); - setIsDeleteModalOpen(false); - }, [policy?.id, policyName]); + + // If the workspace being deleted is the active workspace, switch to the "All Workspaces" view + if (activeWorkspaceID === policy?.id) { + setActiveWorkspaceID(undefined); + Navigation.navigateWithSwitchPolicyID({policyID: undefined}); + } + }, [policy?.id, policyName, activeWorkspaceID, setActiveWorkspaceID]); return ( (); @@ -132,6 +134,12 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r Policy.deleteWorkspace(policyIDToDelete, policyNameToDelete); setIsDeleteModalOpen(false); + + // If the workspace being deleted is the active workspace, switch to the All Workspaces view + if (activeWorkspaceID === policyIDToDelete) { + setActiveWorkspaceID(undefined); + Navigation.navigateWithSwitchPolicyID({policyID: undefined}); + } }; /** From c978394f3867ef8e195d1547ac0b69b21f26c2fa Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 15 Mar 2024 16:45:14 +0530 Subject: [PATCH 2/2] modify comment --- src/pages/workspace/WorkspacesListPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 47b9585ea7fd..959bded29439 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -135,7 +135,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r Policy.deleteWorkspace(policyIDToDelete, policyNameToDelete); setIsDeleteModalOpen(false); - // If the workspace being deleted is the active workspace, switch to the All Workspaces view + // If the workspace being deleted is the active workspace, switch to the "All Workspaces" view if (activeWorkspaceID === policyIDToDelete) { setActiveWorkspaceID(undefined); Navigation.navigateWithSwitchPolicyID({policyID: undefined});