mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2025-12-01 03:47:55 +08:00
fix: issue that refresh workspace list when deleting workspace (#28)
This commit is contained in:
@@ -2970,7 +2970,7 @@
|
||||
"subscribe": {
|
||||
"upgradePlanTitle": "Compare & select plan",
|
||||
"yearly": "Yearly",
|
||||
"save": "Save {discount}%",
|
||||
"save": "Save {{discount}}%",
|
||||
"monthly": "Monthly",
|
||||
"priceIn": "Price in ",
|
||||
"free": "Free",
|
||||
|
||||
@@ -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);
|
||||
}}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -61,6 +61,13 @@ function WorkspaceList ({
|
||||
onUpdateCurrentWorkspace?.(name);
|
||||
}
|
||||
}}
|
||||
onDeleted={() => {
|
||||
if (workspace.id === currentWorkspaceId) {
|
||||
window.location.href = `/app`;
|
||||
} else {
|
||||
void fetchWorkspaces();
|
||||
}
|
||||
}}
|
||||
/></div>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user