From 73d5b2081a0306939855fd8939bb6a9a3df5e3ff Mon Sep 17 00:00:00 2001 From: Himself65 Date: Fri, 28 Apr 2023 01:26:14 -0500 Subject: [PATCH] feat(electron): enable disable cloud alert (#2184) --- apps/electron/tests/basic.spec.ts | 18 ++++++++++++++++ apps/web/src/atoms/index.ts | 2 ++ .../tmp-disable-affine-cloud-modal/index.tsx | 9 +++++++- apps/web/src/components/pure/footer/index.tsx | 15 +++++++------ apps/web/src/providers/ModalProvider.tsx | 21 +++++++++++++++++++ 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/apps/electron/tests/basic.spec.ts b/apps/electron/tests/basic.spec.ts index 5e42b583e7..cccb6ab268 100644 --- a/apps/electron/tests/basic.spec.ts +++ b/apps/electron/tests/basic.spec.ts @@ -21,3 +21,21 @@ test('new page', async () => { expect(flavour).toBe('local'); await electronApp.close(); }); + +test('affine cloud disabled', async () => { + const electronApp = await electron.launch({ + args: [resolve(__dirname, '..')], + executablePath: resolve(__dirname, '../node_modules/.bin/electron'), + }); + const page = await electronApp.firstWindow(); + await page.getByTestId('new-page-button').click({ + delay: 100, + }); + await page.waitForSelector('v-line'); + await page.getByTestId('current-workspace').click(); + await page.getByTestId('sign-in-button').click(); + await page.getByTestId('disable-affine-cloud-modal').waitFor({ + state: 'visible', + }); + await electronApp.close(); +}); diff --git a/apps/web/src/atoms/index.ts b/apps/web/src/atoms/index.ts index 1610ac804e..176563fd6a 100644 --- a/apps/web/src/atoms/index.ts +++ b/apps/web/src/atoms/index.ts @@ -78,6 +78,8 @@ export const openWorkspacesModalAtom = atom(false); export const openCreateWorkspaceModalAtom = atom(false); export const openQuickSearchModalAtom = atom(false); +export const openDisableCloudAlertModalAtom = atom(false); + export { workspacesAtom } from './root'; type View = { id: string; mode: 'page' | 'edgeless' }; diff --git a/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx b/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx index e04354485d..5b7cce3530 100644 --- a/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx +++ b/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx @@ -21,7 +21,11 @@ export const TmpDisableAffineCloudModal: React.FC< TmpDisableAffineCloudModalProps > = ({ open, onClose }) => { return ( - +
click here diff --git a/apps/web/src/components/pure/footer/index.tsx b/apps/web/src/components/pure/footer/index.tsx index ff3362b956..e4a2f37a3f 100644 --- a/apps/web/src/components/pure/footer/index.tsx +++ b/apps/web/src/components/pure/footer/index.tsx @@ -5,10 +5,12 @@ import { config } from '@affine/env'; import { useTranslation } from '@affine/i18n'; import type { AccessTokenMessage } from '@affine/workspace/affine/login'; import { CloudWorkspaceIcon, SignOutIcon } from '@blocksuite/icons'; +import { useSetAtom } from 'jotai'; import type { CSSProperties } from 'react'; import type React from 'react'; import { forwardRef } from 'react'; +import { openDisableCloudAlertModalAtom } from '../../../atoms'; import { stringToColour } from '../../../utils'; import { StyledFooter, StyledSignInButton, StyleUserInfo } from './styles'; @@ -20,11 +22,7 @@ export type FooterProps = { export const Footer: React.FC = ({ user, onLogin, onLogout }) => { const { t } = useTranslation(); - - if (!config.enableLegacyCloud) { - return null; - } - + const setOpen = useSetAtom(openDisableCloudAlertModalAtom); return ( {user && ( @@ -55,6 +53,7 @@ export const Footer: React.FC = ({ user, onLogin, onLogout }) => { {!user && ( = ({ user, onLogin, onLogout }) => { } onClick={async () => { - onLogin(); + if (!config.enableLegacyCloud) { + setOpen(true); + } else { + onLogin(); + } }} > {t('Sign in')} diff --git a/apps/web/src/providers/ModalProvider.tsx b/apps/web/src/providers/ModalProvider.tsx index 47aa9ad646..4172292ab2 100644 --- a/apps/web/src/providers/ModalProvider.tsx +++ b/apps/web/src/providers/ModalProvider.tsx @@ -8,6 +8,7 @@ import { lazy, Suspense, useCallback, useTransition } from 'react'; import { currentWorkspaceIdAtom, openCreateWorkspaceModalAtom, + openDisableCloudAlertModalAtom, openWorkspacesModalAtom, } from '../atoms'; import { useAffineLogIn } from '../hooks/affine/use-affine-log-in'; @@ -29,6 +30,14 @@ const CreateWorkspaceModal = lazy(() => })) ); +const TmpDisableAffineCloudModal = lazy(() => + import('../components/affine/tmp-disable-affine-cloud-modal').then( + module => ({ + default: module.TmpDisableAffineCloudModal, + }) + ) +); + export function Modals() { const [openWorkspacesModal, setOpenWorkspacesModal] = useAtom( openWorkspacesModalAtom @@ -37,6 +46,10 @@ export function Modals() { openCreateWorkspaceModalAtom ); + const [openDisableCloudAlertModal, setOpenDisableCloudAlertModal] = useAtom( + openDisableCloudAlertModalAtom + ); + const router = useRouter(); const { jumpToSubPath } = useRouterHelper(router); const user = useCurrentUser(); @@ -49,6 +62,14 @@ export function Modals() { return ( <> + + { + setOpenDisableCloudAlertModal(false); + }, [setOpenDisableCloudAlertModal])} + /> +