mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2025-12-01 11:57:53 +08:00
fix: issue that refresh workspace list when deleting workspace (#28)
This commit is contained in:
@@ -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",
|
||||||
|
|||||||
@@ -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);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -5,41 +5,45 @@ 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;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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
|
||||||
setConfirmOpen(true);
|
onClick={() => {
|
||||||
}} className={'w-full justify-start hover:text-function-error'} size={'small'} color={'inherit'} startIcon={<DeleteSvg />}>
|
setConfirmOpen(true);
|
||||||
|
}}
|
||||||
|
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
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ function WorkspaceList ({
|
|||||||
onUpdateCurrentWorkspace?.(name);
|
onUpdateCurrentWorkspace?.(name);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onDeleted={() => {
|
||||||
|
if (workspace.id === currentWorkspaceId) {
|
||||||
|
window.location.href = `/app`;
|
||||||
|
} else {
|
||||||
|
void fetchWorkspaces();
|
||||||
|
}
|
||||||
|
}}
|
||||||
/></div>;
|
/></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user