From 764da784ae909785032bec73f977be00ced80bf8 Mon Sep 17 00:00:00 2001 From: EYHN Date: Tue, 30 Apr 2024 04:46:08 +0000 Subject: [PATCH] feat(core): add enable cloud failed notify (#6741) --- .../component/src/ui/modal/confirm-modal.tsx | 1 + .../src/hooks/affine/use-enable-cloud.tsx | 23 +++++++++++++------ packages/frontend/i18n/src/resources/en.json | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/frontend/component/src/ui/modal/confirm-modal.tsx b/packages/frontend/component/src/ui/modal/confirm-modal.tsx index c0817ee488..bdff9e96ed 100644 --- a/packages/frontend/component/src/ui/modal/confirm-modal.tsx +++ b/packages/frontend/component/src/ui/modal/confirm-modal.tsx @@ -112,6 +112,7 @@ export const ConfirmModalProvider = ({ children }: PropsWithChildren) => { return Promise.resolve(_onConfirm?.()) .then(() => onSuccess?.()) .catch(console.error) + .finally(() => setLoading(false)) .finally(() => autoClose && closeConfirmModal()); }; setModalProps({ ...otherProps, onConfirm, open: true }); diff --git a/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx b/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx index a26e28b13f..76b143a5ca 100644 --- a/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx +++ b/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx @@ -1,4 +1,4 @@ -import { useConfirmModal } from '@affine/component'; +import { notify, useConfirmModal } from '@affine/component'; import { authAtom } from '@affine/core/atoms'; import { AuthService } from '@affine/core/modules/cloud'; import { WorkspaceSubPath } from '@affine/core/shared'; @@ -37,12 +37,19 @@ export const useEnableCloud = () => { const enableCloud = useCallback( async (ws: Workspace | null, options?: ConfirmEnableCloudOptions) => { - if (!ws) return; - const { id: newId } = await workspacesService.transformLocalToCloud(ws); - openPage(newId, options?.openPageId || WorkspaceSubPath.ALL); - options?.onSuccess?.(); + try { + if (!ws) return; + const { id: newId } = await workspacesService.transformLocalToCloud(ws); + openPage(newId, options?.openPageId || WorkspaceSubPath.ALL); + options?.onSuccess?.(); + } catch (e) { + console.error(e); + notify.error({ + title: t['com.affine.workspace.enable-cloud.failed'](), + }); + } }, - [openPage, workspacesService] + [openPage, t, workspacesService] ); const openSignIn = useCallback(() => { @@ -95,7 +102,9 @@ export const useEnableCloud = () => { if (!open) onFinished?.(); }, }, - { autoClose: false } + { + autoClose: false, + } ); }, [closeConfirmModal, loginStatus, openConfirmModal, signInOrEnableCloud, t] diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.json index 77fdc68bc5..0177c27e47 100644 --- a/packages/frontend/i18n/src/resources/en.json +++ b/packages/frontend/i18n/src/resources/en.json @@ -1312,5 +1312,6 @@ "com.affine.ai.login-required.dialog-content": "To use AFFiNE AI, please sign in to your AFFiNE Cloud account.", "com.affine.ai.login-required.dialog-confirm": "Sign in", "com.affine.ai.login-required.dialog-cancel": "Cancel", - "com.affine.ai.action.edgeless-only.dialog-title": "Please switch to edgeless mode" + "com.affine.ai.action.edgeless-only.dialog-title": "Please switch to edgeless mode", + "com.affine.workspace.enable-cloud.failed": "Failed to enable Cloud, please try again." }