feat:add leave workspace

This commit is contained in:
DiamondThree 2023-01-12 15:52:07 +08:00
parent 14c665757e
commit ede7a6bdaa
3 changed files with 30 additions and 36 deletions

View File

@ -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 }) => {
<StyledDeleteButtonContainer>
{isOwner ? (
<>
<Button type="danger" shape="circle" onClick={handleClickDelete}>
<Button
type="danger"
shape="circle"
onClick={() => {
setShowDelete(true);
}}
>
Delete Workspace
</Button>
<WorkspaceDelete
open={showDelete}
onClose={handleCloseDelete}
onClose={() => {
setShowDelete(false);
}}
workspace={workspace}
/>
</>
) : (
<>
<Button type="danger" shape="circle" onClick={handleClickLeave}>
<Button
type="danger"
shape="circle"
onClick={() => {
setShowLeave(true);
}}
>
Leave Workspace
</Button>
<WorkspaceLeave
open={showLeave}
onClose={handleCloseLeave}
workspaceName={workspaceName}
workspaceId={workspace.id}
onClose={() => {
setShowLeave(false);
}}
/>
</>
)}

View File

@ -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();
};

View File

@ -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,
};
};