Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to all workspace view when workspace is deleted #38365

Merged
merged 3 commits into from
Mar 17, 2024
Merged
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
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
Loading