fix: delete workspace in settings (#3030)

This commit is contained in:
Peng Xiao 2023-07-05 18:31:11 +08:00 committed by GitHub
parent 776172bc88
commit dec0c0d3d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View File

@ -20,7 +20,7 @@ interface WorkspaceDeleteProps {
open: boolean;
onClose: () => void;
workspace: AffineOfficialWorkspace;
onDeleteWorkspace: () => Promise<void>;
onDeleteWorkspace: (id: string) => Promise<void>;
}
export const WorkspaceDeleteModal = ({
@ -37,16 +37,17 @@ export const WorkspaceDeleteModal = ({
const t = useAFFiNEI18N();
const handleDelete = useCallback(() => {
onDeleteWorkspace()
onDeleteWorkspace(workspace.id)
.then(() => {
toast(t['Successfully deleted'](), {
portal: document.body,
});
onClose();
})
.catch(() => {
// ignore error
});
}, [onDeleteWorkspace, t]);
}, [onClose, onDeleteWorkspace, t, workspace.id]);
return (
<Modal open={open} onClose={onClose}>

View File

@ -20,7 +20,7 @@ import { StoragePanel } from './storage';
export type WorkspaceSettingDetailProps = {
workspace: AffineOfficialWorkspace;
onDeleteWorkspace: () => Promise<void>;
onDeleteWorkspace: (id: string) => Promise<void>;
onTransferWorkspace: <
From extends WorkspaceFlavour,
To extends WorkspaceFlavour

View File

@ -1,5 +1,4 @@
import { assertExists } from '@blocksuite/global/utils';
import React, { Suspense, useCallback } from 'react';
import { Suspense, useCallback } from 'react';
import { getUIAdapter } from '../../../../adapters/workspace';
import { useOnTransformWorkspace } from '../../../../hooks/root/use-on-transform-workspace';
@ -10,11 +9,12 @@ export const WorkSpaceSetting = ({ workspace }: { workspace: Workspace }) => {
const helper = useAppHelper();
const { NewSettingsDetail } = getUIAdapter(workspace.flavour);
const onDeleteWorkspace = useCallback(async () => {
assertExists(currentWorkspace);
const workspaceId = currentWorkspace.id;
return helper.deleteWorkspace(workspaceId);
}, [helper]);
const onDeleteWorkspace = useCallback(
async (id: string) => {
return helper.deleteWorkspace(id);
},
[helper]
);
const onTransformWorkspace = useOnTransformWorkspace();
return (

View File

@ -131,7 +131,7 @@ export type WorkspaceHeaderProps<Flavour extends keyof WorkspaceRegistry> =
type NewSettingProps<Flavour extends keyof WorkspaceRegistry> =
UIBaseProps<Flavour> & {
onDeleteWorkspace: () => Promise<void>;
onDeleteWorkspace: (id: string) => Promise<void>;
onTransformWorkspace: <
From extends keyof WorkspaceRegistry,
To extends keyof WorkspaceRegistry