From d9d60197f2538327a6600a28ebf609fb24a8c7c8 Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Tue, 7 Feb 2023 20:01:25 +0800 Subject: [PATCH] fix:delete workspace will jump to 404 --- .../app/src/components/workspace-modal/index.tsx | 1 - .../workspace-setting/general/delete/Delete.tsx | 3 --- packages/app/src/hooks/use-ensure-workspace.ts | 12 ++++++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/app/src/components/workspace-modal/index.tsx b/packages/app/src/components/workspace-modal/index.tsx index 4dd552eac..91b354946 100644 --- a/packages/app/src/components/workspace-modal/index.tsx +++ b/packages/app/src/components/workspace-modal/index.tsx @@ -132,7 +132,6 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => { onClose={async wait => { if (!wait) { await logout(); - router.push(`/workspace`); } setLogoutOpen(false); }} diff --git a/packages/app/src/components/workspace-setting/general/delete/Delete.tsx b/packages/app/src/components/workspace-setting/general/delete/Delete.tsx index 3fcab8c15..d8b0858de 100644 --- a/packages/app/src/components/workspace-setting/general/delete/Delete.tsx +++ b/packages/app/src/components/workspace-setting/general/delete/Delete.tsx @@ -11,7 +11,6 @@ import { import { useState } from 'react'; import { ModalCloseButton } from '@/ui/modal'; import { Button } from '@/ui/button'; -import { useRouter } from 'next/router'; import { WorkspaceUnit } from '@affine/datacenter'; import { Trans, useTranslation } from '@affine/i18n'; @@ -30,7 +29,6 @@ export const WorkspaceDelete = ({ }: WorkspaceDeleteProps) => { const [deleteStr, setDeleteStr] = useState(''); const { t } = useTranslation(); - const router = useRouter(); const { deleteWorkSpace } = useWorkspaceHelper(); const handlerInputChange = (workspaceName: string) => { setDeleteStr(workspaceName); @@ -39,7 +37,6 @@ export const WorkspaceDelete = ({ const handleDelete = async () => { await deleteWorkSpace(); onClose(); - router.push(`/workspace`); }; return ( diff --git a/packages/app/src/hooks/use-ensure-workspace.ts b/packages/app/src/hooks/use-ensure-workspace.ts index d547b09da..08181c414 100644 --- a/packages/app/src/hooks/use-ensure-workspace.ts +++ b/packages/app/src/hooks/use-ensure-workspace.ts @@ -5,7 +5,7 @@ import { useRouter } from 'next/router'; // Cause it not just ensure workspace loaded, but also have router change. export const useEnsureWorkspace = () => { const [workspaceLoaded, setWorkspaceLoaded] = useState(false); - const { workspaceList, loadWorkspace, user } = useAppState(); + const { dataCenter, loadWorkspace, user } = useAppState(); const router = useRouter(); const [activeWorkspaceId, setActiveWorkspaceId] = useState( router.query.workspaceId as string @@ -17,14 +17,14 @@ export const useEnsureWorkspace = () => { // If router.query.workspaceId is not in workspace list, jump to 404 page // If workspaceList is empty, we need to create a default workspace but not jump to 404 if ( - workspaceList.length && + dataCenter.workspaces.length && // FIXME: router is not ready when this hook is called location.pathname.startsWith(`/workspace/${router.query.workspaceId}`) && - workspaceList.findIndex( + dataCenter.workspaces.findIndex( meta => meta.id.toString() === router.query.workspaceId ) === -1 ) { - router.push('/404'); + router.push(`/workspace/${dataCenter.workspaces[0].id}`); return; } // If user is not login and input a custom workspaceId, jump to 404 page @@ -37,12 +37,12 @@ export const useEnsureWorkspace = () => { // return; // } const workspaceId = - (router.query.workspaceId as string) || workspaceList[0]?.id; + (router.query.workspaceId as string) || dataCenter.workspaces[0]?.id; loadWorkspace.current(workspaceId).finally(() => { setWorkspaceLoaded(true); setActiveWorkspaceId(activeWorkspaceId); }); - }, [loadWorkspace, router, user, workspaceList, activeWorkspaceId]); + }, [loadWorkspace, router, user, dataCenter.workspaces, activeWorkspaceId]); return { workspaceLoaded,