From ede7a6bdaa9c3f03fe30ebf2b8502db2a9121236 Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Thu, 12 Jan 2023 15:52:07 +0800 Subject: [PATCH] feat:add leave workspace --- .../workspace-setting/general/General.tsx | 40 +++++++++---------- .../workspace-setting/general/leave/Leave.tsx | 18 ++------- .../app/src/hooks/use-workspace-helper.ts | 8 +++- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/packages/app/src/components/workspace-setting/general/General.tsx b/packages/app/src/components/workspace-setting/general/General.tsx index 65e87496d0..b3f5af88a1 100644 --- a/packages/app/src/components/workspace-setting/general/General.tsx +++ b/packages/app/src/components/workspace-setting/general/General.tsx @@ -27,26 +27,12 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => { const handleChangeWorkSpaceName = (newName: string) => { setWorkspaceName(newName); }; - const handleClickDelete = () => { - setShowDelete(true); - }; - const handleCloseDelete = () => { - setShowDelete(false); - }; - - const handleClickLeave = () => { - setShowLeave(true); - }; - const handleCloseLeave = () => { - setShowLeave(false); - }; const handleUpdateWorkspaceName = () => { currentWorkspace && updateWorkspace({ name: workspaceName }, currentWorkspace); }; const fileChange = async (file: File) => { - // console.log('file: ', file); setUploading(true); const blob = new Blob([file], { type: file.type }); currentWorkspace && @@ -104,25 +90,39 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => { {isOwner ? ( <> - { + setShowDelete(false); + }} workspace={workspace} /> ) : ( <> - { + setShowLeave(false); + }} /> )} diff --git a/packages/app/src/components/workspace-setting/general/leave/Leave.tsx b/packages/app/src/components/workspace-setting/general/leave/Leave.tsx index e34b4ac257..aed3617abc 100644 --- a/packages/app/src/components/workspace-setting/general/leave/Leave.tsx +++ b/packages/app/src/components/workspace-setting/general/leave/Leave.tsx @@ -7,29 +7,19 @@ import { } from './style'; import { ModalCloseButton } from '@/ui/modal'; import { Button } from '@/ui/button'; +import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; // import { getDataCenter } from '@affine/datacenter'; // import { useAppState } from '@/providers/app-state-provider'; interface WorkspaceDeleteProps { open: boolean; onClose: () => void; - workspaceName: string; - workspaceId: string; } -export const WorkspaceLeave = ({ - open, - onClose, - workspaceId, -}: WorkspaceDeleteProps) => { - console.log('workspaceId: ', workspaceId); - // const router = useRouter(); - // const { refreshWorkspacesMeta } = useAppState(); +export const WorkspaceLeave = ({ open, onClose }: WorkspaceDeleteProps) => { + const { leaveWorkSpace } = useWorkspaceHelper(); const handleLeave = async () => { - // const dc = await getDataCenter(); - // await dc.apis.leaveWorkspace({ id: workspaceId }); - // // router.push(`/workspace/${nextWorkSpaceId}`); - // refreshWorkspacesMeta(); + await leaveWorkSpace(); onClose(); }; diff --git a/packages/app/src/hooks/use-workspace-helper.ts b/packages/app/src/hooks/use-workspace-helper.ts index c8e05d6e2c..f1dee901d3 100644 --- a/packages/app/src/hooks/use-workspace-helper.ts +++ b/packages/app/src/hooks/use-workspace-helper.ts @@ -47,10 +47,10 @@ export const useWorkspaceHelper = () => { if (!user) { await login(); } - const newWorkspaceId = await dataCenter.enableWorkspaceCloud( + const workspace = await dataCenter.enableWorkspaceCloud( currentWorkspace ); - router.push(`/workspace/${newWorkspaceId}/setting`); + workspace && router.push(`/workspace/${workspace.id}/setting`); toast('Enabled success'); } }); @@ -60,6 +60,9 @@ export const useWorkspaceHelper = () => { currentWorkspace && (await dataCenter.deleteWorkspace(currentWorkspace?.id)); }; + const leaveWorkSpace = async () => { + currentWorkspace && (await dataCenter.leaveWorkspace(currentWorkspace?.id)); + }; return { createWorkspace, @@ -67,5 +70,6 @@ export const useWorkspaceHelper = () => { updateWorkspace, enableWorkspace, deleteWorkSpace, + leaveWorkSpace, }; };