Skip to content

Commit

Permalink
Merge pull request #38365 from ishpaul777/fix/38277
Browse files Browse the repository at this point in the history
  • Loading branch information
mountiny authored Mar 17, 2024
2 parents e40fba1 + c978394 commit c915e7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ?? '';
Expand Down Expand Up @@ -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 (
<WorkspacePageWithSections
headerText={translate('workspace.common.profile')}
Expand Down
8 changes: 8 additions & 0 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {PressableWithoutFeedback} from '@components/Pressable';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -119,6 +120,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions();
const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace();

const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [policyIDToDelete, setPolicyIDToDelete] = useState<string>();
Expand All @@ -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});
}
};

/**
Expand Down

0 comments on commit c915e7f

Please sign in to comment.