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": { "subscribe": {
"upgradePlanTitle": "Compare & select plan", "upgradePlanTitle": "Compare & select plan",
"yearly": "Yearly", "yearly": "Yearly",
"save": "Save {discount}%", "save": "Save {{discount}}%",
"monthly": "Monthly", "monthly": "Monthly",
"priceIn": "Price in ", "priceIn": "Price in ",
"free": "Free", "free": "Free",

View File

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

View File

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

View File

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

View File

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