mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
feat:add logout
This commit is contained in:
@@ -7,6 +7,7 @@ import { KeyboardEvent } from 'react';
|
|||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
|
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
import { toast } from '@/ui/toast';
|
||||||
|
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -23,7 +24,7 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
router.replace(`/workspace/${workspace.id}`);
|
router.replace(`/workspace/${workspace.id}`);
|
||||||
onClose();
|
onClose();
|
||||||
} else {
|
} else {
|
||||||
console.log('create error');
|
toast('create error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { styled } from '@/styles';
|
|||||||
import { Modal, ModalWrapper, ModalCloseButton } from '@/ui/modal';
|
import { Modal, ModalWrapper, ModalCloseButton } from '@/ui/modal';
|
||||||
import { Button } from '@/ui/button';
|
import { Button } from '@/ui/button';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { SignOut } from '@/hooks/mock-data/mock';
|
|
||||||
import { CreateWorkspaceModal } from '../create-workspace';
|
import { CreateWorkspaceModal } from '../create-workspace';
|
||||||
import {
|
import {
|
||||||
CloudUnsyncedIcon,
|
CloudUnsyncedIcon,
|
||||||
@@ -14,6 +13,7 @@ import { toast } from '@/ui/toast';
|
|||||||
import { WorkspaceAvatar } from '@/components/workspace-avatar';
|
import { WorkspaceAvatar } from '@/components/workspace-avatar';
|
||||||
import { useAppState } from '@/providers/app-state-provider';
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
import { useConfirm } from '@/providers/ConfirmProvider';
|
||||||
|
|
||||||
interface WorkspaceModalProps {
|
interface WorkspaceModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -22,8 +22,9 @@ interface WorkspaceModalProps {
|
|||||||
|
|
||||||
export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
||||||
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
|
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
|
||||||
// const { confirm } = useConfirm();
|
const { confirm } = useConfirm();
|
||||||
const { workspaceList, currentWorkspace, login, user } = useAppState();
|
const { workspaceList, currentWorkspace, login, user, logout } =
|
||||||
|
useAppState();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -134,9 +135,9 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
|||||||
<Footer>
|
<Footer>
|
||||||
{!user ? (
|
{!user ? (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
login();
|
await login();
|
||||||
toast('login success');
|
toast('Login success');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Sign in AFFiNE Cloud
|
Sign in AFFiNE Cloud
|
||||||
@@ -144,7 +145,20 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
SignOut();
|
confirm({
|
||||||
|
title: 'Sign out?',
|
||||||
|
content: `All data has been stored in the cloud. `,
|
||||||
|
confirmText: 'Sign out',
|
||||||
|
cancelText: 'Cancel',
|
||||||
|
}).then(async confirm => {
|
||||||
|
if (confirm) {
|
||||||
|
if (user) {
|
||||||
|
await logout();
|
||||||
|
router.replace(`/workspace`);
|
||||||
|
toast('Enabled success');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Sign out of AFFiNE Cloud
|
Sign out of AFFiNE Cloud
|
||||||
|
|||||||
Reference in New Issue
Block a user