feat(electron): enable disable cloud alert (#2184)

This commit is contained in:
Himself65 2023-04-28 01:26:14 -05:00 committed by GitHub
parent 70fbbb39c1
commit 73d5b2081a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 7 deletions

View File

@ -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();
});

View File

@ -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' };

View File

@ -21,7 +21,11 @@ export const TmpDisableAffineCloudModal: React.FC<
TmpDisableAffineCloudModalProps
> = ({ open, onClose }) => {
return (
<Modal open={open} onClose={onClose}>
<Modal
data-testid="disable-affine-cloud-modal"
open={open}
onClose={onClose}
>
<ModalWrapper width={480}>
<Header>
<IconButton
@ -41,6 +45,9 @@ export const TmpDisableAffineCloudModal: React.FC<
<a
href="https://github.com/toeverything/AFFiNE/releases"
target="_blank"
style={{
color: 'var(--affine-link-color)',
}}
>
click here
</a>

View File

@ -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<FooterProps> = ({ user, onLogin, onLogout }) => {
const { t } = useTranslation();
if (!config.enableLegacyCloud) {
return null;
}
const setOpen = useSetAtom(openDisableCloudAlertModalAtom);
return (
<StyledFooter data-testid="workspace-list-modal-footer">
{user && (
@ -55,6 +53,7 @@ export const Footer: React.FC<FooterProps> = ({ user, onLogin, onLogout }) => {
{!user && (
<StyledSignInButton
data-testid="sign-in-button"
noBorder
bold
icon={
@ -63,7 +62,11 @@ export const Footer: React.FC<FooterProps> = ({ user, onLogin, onLogout }) => {
</div>
}
onClick={async () => {
onLogin();
if (!config.enableLegacyCloud) {
setOpen(true);
} else {
onLogin();
}
}}
>
{t('Sign in')}

View File

@ -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 (
<>
<Suspense>
<TmpDisableAffineCloudModal
open={openDisableCloudAlertModal}
onClose={useCallback(() => {
setOpenDisableCloudAlertModal(false);
}, [setOpenDisableCloudAlertModal])}
/>
</Suspense>
<Suspense>
<WorkspaceListModal
disabled={transitioning}