mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 19:40:30 +08:00
feat(core): add more notification types (#11156)
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
||||
} from '@affine/graphql';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const ChangePasswordDialog = ({
|
||||
close,
|
||||
@@ -52,10 +52,12 @@ export const ChangePasswordDialog = ({
|
||||
);
|
||||
const serverName = useLiveData(server.config$.selector(c => c.serverName));
|
||||
|
||||
if (!email) {
|
||||
// should not happen
|
||||
throw new Unreachable();
|
||||
}
|
||||
useEffect(() => {
|
||||
if (!account) {
|
||||
// we are logged out, close the dialog
|
||||
close();
|
||||
}
|
||||
}, [account, close]);
|
||||
|
||||
const onSendEmail = useAsyncCallback(async () => {
|
||||
setLoading(true);
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
ExpiredPage,
|
||||
JoinFailedPage,
|
||||
} from '@affine/component/member-components';
|
||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||
import { WorkspacesService } from '@affine/core/modules/workspace';
|
||||
import { UserFriendlyError } from '@affine/error';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
@@ -17,6 +19,7 @@ import { AcceptInviteService, AuthService } from '../../../modules/cloud';
|
||||
const AcceptInvite = ({ inviteId: targetInviteId }: { inviteId: string }) => {
|
||||
const { jumpToPage } = useNavigateHelper();
|
||||
const acceptInviteService = useService(AcceptInviteService);
|
||||
const workspacesService = useService(WorkspacesService);
|
||||
const error = useLiveData(acceptInviteService.error$);
|
||||
const inviteId = useLiveData(acceptInviteService.inviteId$);
|
||||
const inviteInfo = useLiveData(acceptInviteService.inviteInfo$);
|
||||
@@ -24,19 +27,20 @@ const AcceptInvite = ({ inviteId: targetInviteId }: { inviteId: string }) => {
|
||||
const loading = useLiveData(acceptInviteService.loading$);
|
||||
const navigateHelper = useNavigateHelper();
|
||||
|
||||
const openWorkspace = useCallback(() => {
|
||||
const openWorkspace = useAsyncCallback(async () => {
|
||||
if (!inviteInfo?.workspace.id) {
|
||||
return;
|
||||
}
|
||||
await workspacesService.list.waitForRevalidation();
|
||||
jumpToPage(inviteInfo.workspace.id, 'all', RouteLogic.REPLACE);
|
||||
}, [jumpToPage, inviteInfo]);
|
||||
}, [inviteInfo, workspacesService, jumpToPage]);
|
||||
|
||||
const onOpenAffine = useCallback(() => {
|
||||
navigateHelper.jumpToIndex();
|
||||
}, [navigateHelper]);
|
||||
|
||||
useEffect(() => {
|
||||
acceptInviteService.revalidate({
|
||||
acceptInviteService.acceptInvite({
|
||||
inviteId: targetInviteId,
|
||||
});
|
||||
}, [acceptInviteService, targetInviteId]);
|
||||
@@ -45,10 +49,10 @@ const AcceptInvite = ({ inviteId: targetInviteId }: { inviteId: string }) => {
|
||||
if (error && inviteId === targetInviteId) {
|
||||
const err = UserFriendlyError.fromAny(error);
|
||||
if (err.is('ALREADY_IN_SPACE')) {
|
||||
return navigateHelper.jumpToIndex();
|
||||
return openWorkspace();
|
||||
}
|
||||
}
|
||||
}, [error, inviteId, navigateHelper, targetInviteId]);
|
||||
}, [error, inviteId, navigateHelper, openWorkspace, targetInviteId]);
|
||||
|
||||
if (loading || inviteId !== targetInviteId) {
|
||||
return null;
|
||||
|
||||
@@ -123,17 +123,20 @@ export const Component = (): ReactElement => {
|
||||
// if workspace is not found, we should retry
|
||||
const retryTimesRef = useRef(3);
|
||||
useEffect(() => {
|
||||
retryTimesRef.current = 3; // reset retry times
|
||||
}, [params.workspaceId]);
|
||||
if (params.workspaceId) {
|
||||
retryTimesRef.current = 3; // reset retry times
|
||||
workspacesService.list.revalidate();
|
||||
}
|
||||
}, [params.workspaceId, workspacesService]);
|
||||
useEffect(() => {
|
||||
if (listLoading === false && meta === undefined) {
|
||||
const timer = setInterval(() => {
|
||||
const timer = setTimeout(() => {
|
||||
if (retryTimesRef.current > 0) {
|
||||
workspacesService.list.revalidate();
|
||||
retryTimesRef.current--;
|
||||
}
|
||||
}, 5000);
|
||||
return () => clearInterval(timer);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
return;
|
||||
}, [listLoading, meta, workspaceNotFound, workspacesService]);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||
import type { SettingTab } from '@affine/core/modules/dialogs/constant';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
export const Component = () => {
|
||||
const workbenchService = useService(WorkbenchService);
|
||||
const workspaceDialogService = useService(WorkspaceDialogService);
|
||||
const workbench = workbenchService.workbench;
|
||||
|
||||
const [searchParams] = useSearchParams();
|
||||
const tab = searchParams.get('tab') ?? undefined;
|
||||
|
||||
const isOpened = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpened.current) {
|
||||
return;
|
||||
}
|
||||
isOpened.current = true; // prevent open multiple times
|
||||
workbench.openAll();
|
||||
workspaceDialogService.open('setting', {
|
||||
activeTab: tab as SettingTab,
|
||||
});
|
||||
}, [tab, workbench, workspaceDialogService]);
|
||||
return null;
|
||||
};
|
||||
@@ -37,6 +37,10 @@ export const workbenchRoutes = [
|
||||
path: '/journals',
|
||||
lazy: () => import('./pages/journals'),
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
lazy: () => import('./pages/workspace/settings'),
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
lazy: () => import('./pages/404'),
|
||||
|
||||
Reference in New Issue
Block a user