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

View File

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

View File

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

View File

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