Skip to content

Commit

Permalink
feat(core): add enable cloud failed notify (#6741)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Apr 30, 2024
1 parent 148e058 commit 764da78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/frontend/component/src/ui/modal/confirm-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
23 changes: 16 additions & 7 deletions packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -95,7 +102,9 @@ export const useEnableCloud = () => {
if (!open) onFinished?.();
},
},
{ autoClose: false }
{
autoClose: false,
}
);
},
[closeConfirmModal, loginStatus, openConfirmModal, signInOrEnableCloud, t]
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/i18n/src/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

0 comments on commit 764da78

Please sign in to comment.