Merge pull request #886 from toeverything/feat/sync-status

fix: logout will jump to 404 error
This commit is contained in:
DarkSky
2023-02-08 23:22:10 +08:00
committed by GitHub
7 changed files with 72 additions and 52 deletions
@@ -51,26 +51,49 @@ export const LogoutModal = ({ open, onClose }: LoginModalProps) => {
)}
{t('Retain local cached data')}
</StyleTips>
<div>
<Button
style={{ marginRight: '16px' }}
shape="round"
onClick={() => {
onClose(true);
}}
>
{t('Wait for Sync')}
</Button>
<Button
type="danger"
shape="round"
onClick={() => {
onClose(false);
}}
>
{t('Force Sign Out')}
</Button>
</div>
{blobDataSynced ? (
<div>
<Button
type="danger"
shape="round"
style={{ marginRight: '16px' }}
onClick={async () => {
onClose(false);
}}
>
{t('Force Sign Out')}
</Button>
<Button
shape="round"
onClick={() => {
onClose(true);
}}
>
{t('Wait for Sync')}
</Button>
</div>
) : (
<div>
<Button
type="primary"
style={{ marginRight: '16px' }}
shape="round"
onClick={() => {
onClose(true);
}}
>
{t('Cancel')}
</Button>
<Button
shape="round"
onClick={() => {
onClose(false);
}}
>
{t('Sign out')}
</Button>
</div>
)}
</Content>
</ModalWrapper>
</Modal>
@@ -36,7 +36,7 @@ interface WorkspaceModalProps {
export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
const { workspaceList, logout } = useAppState();
const { logout, dataCenter } = useAppState();
const router = useRouter();
const { t } = useTranslation();
const [loginOpen, setLoginOpen] = useState(false);
@@ -80,7 +80,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
</StyledModalHeader>
<StyledModalContent>
{workspaceList.map((item, index) => {
{dataCenter.workspaces.map((item, index) => {
return (
<WorkspaceCard
workspaceData={item}
@@ -132,7 +132,11 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
onClose={async wait => {
if (!wait) {
await logout();
router.replace(`/workspace`);
if (dataCenter.workspaces.length === 0) {
router.push(`/workspace`);
} else {
router.push(`/workspace/${dataCenter.workspaces[0].id}`);
}
}
setLogoutOpen(false);
}}
@@ -1,3 +1,4 @@
import { useRouter } from 'next/router';
import Modal from '@/ui/modal';
import Input from '@/ui/input';
import {
@@ -11,7 +12,6 @@ import {
import { useState } from 'react';
import { ModalCloseButton } from '@/ui/modal';
import { Button } from '@/ui/button';
import { useRouter } from 'next/router';
import { WorkspaceUnit } from '@affine/datacenter';
import { Trans, useTranslation } from '@affine/i18n';