fix: issue that refresh workspace list when deleting workspace (#28)

This commit is contained in:
Kilu.He
2025-01-14 15:39:01 +08:00
committed by GitHub
parent b28f566f0a
commit 41dddee71a
5 changed files with 30 additions and 15 deletions

View File

@@ -2970,7 +2970,7 @@
"subscribe": {
"upgradePlanTitle": "Compare & select plan",
"yearly": "Yearly",
"save": "Save {discount}%",
"save": "Save {{discount}}%",
"monthly": "Monthly",
"priceIn": "Price in ",
"free": "Free",

View File

@@ -71,7 +71,6 @@ function ViewItem ({ view, width, level = 0, renderExtra, expandIds, toggleExpan
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
onClick={() => {
console.log('view.layout', view.layout);
if (layout === ViewLayout.AIChat) return;
onClickView?.(viewId);
}}

View File

@@ -5,17 +5,16 @@ import { ReactComponent as DeleteSvg } from '@/assets/trash.svg';
import { NormalModal } from '@/components/_shared/modal';
import { notify } from '@/components/_shared/notify';
import { useService } from '@/components/main/app.hooks';
import { useCurrentWorkspaceId } from '@/components/app/app.hooks';
function DeleteWorkspace({workspaceId, name}: {
function DeleteWorkspace ({ workspaceId, name, onDeleted }: {
name: string;
workspaceId: string;
onDeleted?: () => void;
}) {
const { t } = useTranslation();
const [confirmOpen, setConfirmOpen] = React.useState(false);
const [loading, setLoading] = React.useState(false);
const service = useService();
const currentWorkspaceId = useCurrentWorkspaceId();
const handleOk = async () => {
if (!service) return;
@@ -24,22 +23,27 @@ function DeleteWorkspace({workspaceId, name}: {
setLoading(true);
await service.deleteWorkspace(workspaceId);
setConfirmOpen(false);
if (currentWorkspaceId === workspaceId) {
window.location.href = `/app`
}
onDeleted?.();
// eslint-disable-next-line
} catch (e: any) {
notify.error(e.message);
} finally {
setLoading(false);
}
}
};
return (
<>
<Button onClick={() => {
<Button
onClick={() => {
setConfirmOpen(true);
}} className={'w-full justify-start hover:text-function-error'} size={'small'} color={'inherit'} startIcon={<DeleteSvg />}>
}}
className={'w-full justify-start hover:text-function-error'}
size={'small'}
color={'inherit'}
startIcon={<DeleteSvg />}
>
{t('button.delete')}
</Button>
<NormalModal

View File

@@ -8,9 +8,10 @@ import { useCurrentUser } from '@/components/main/app.hooks';
import DeleteWorkspace from '@/components/app/workspaces/DeleteWorkspace';
import RenameWorkspace from '@/components/app/workspaces/RenameWorkspace';
function MoreActions ({ workspace, onUpdated }: {
function MoreActions ({ workspace, onUpdated, onDeleted }: {
workspace: Workspace;
onUpdated: (name: string) => void;
onDeleted?: () => void;
}) {
const ref = React.useRef<HTMLButtonElement | null>(null);
const [open, setOpen] = React.useState(false);
@@ -56,6 +57,10 @@ function MoreActions ({ workspace, onUpdated }: {
<DeleteWorkspace
name={workspace.name}
workspaceId={workspace.id}
onDeleted={() => {
setOpen(false);
onDeleted?.();
}}
/>
</div>

View File

@@ -61,6 +61,13 @@ function WorkspaceList ({
onUpdateCurrentWorkspace?.(name);
}
}}
onDeleted={() => {
if (workspace.id === currentWorkspaceId) {
window.location.href = `/app`;
} else {
void fetchWorkspaces();
}
}}
/></div>;
}