mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(core): unexpected redirect to expired page after accepting invitation (#10257)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { AuthPageContainer } from '@affine/component/auth-components';
|
||||
import { Button } from '@affine/component/ui/button';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { ExpiredPage } from '@affine/component/member-components';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import {
|
||||
@@ -14,20 +12,10 @@ import {
|
||||
* only on web
|
||||
*/
|
||||
export const Component = () => {
|
||||
const t = useI18n();
|
||||
const { jumpToIndex } = useNavigateHelper();
|
||||
const onOpenAffine = useCallback(() => {
|
||||
jumpToIndex(RouteLogic.REPLACE);
|
||||
}, [jumpToIndex]);
|
||||
|
||||
return (
|
||||
<AuthPageContainer
|
||||
title={t['com.affine.expired.page.title']()}
|
||||
subtitle={t['com.affine.expired.page.new-subtitle']()}
|
||||
>
|
||||
<Button variant="primary" size="large" onClick={onOpenAffine}>
|
||||
{t['com.affine.auth.open.affine']()}
|
||||
</Button>
|
||||
</AuthPageContainer>
|
||||
);
|
||||
return <ExpiredPage onOpenAffine={onOpenAffine} />;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
AcceptInvitePage,
|
||||
ExpiredPage,
|
||||
JoinFailedPage,
|
||||
} from '@affine/component/member-components';
|
||||
import { ErrorNames, UserFriendlyError } from '@affine/graphql';
|
||||
@@ -13,10 +14,11 @@ import {
|
||||
} from '../../../components/hooks/use-navigate-helper';
|
||||
import { AcceptInviteService, AuthService } from '../../../modules/cloud';
|
||||
|
||||
const AcceptInvite = ({ inviteId }: { inviteId: string }) => {
|
||||
const AcceptInvite = ({ inviteId: targetInviteId }: { inviteId: string }) => {
|
||||
const { jumpToPage } = useNavigateHelper();
|
||||
const acceptInviteService = useService(AcceptInviteService);
|
||||
const error = useLiveData(acceptInviteService.error$);
|
||||
const inviteId = useLiveData(acceptInviteService.inviteId$);
|
||||
const inviteInfo = useLiveData(acceptInviteService.inviteInfo$);
|
||||
const accepted = useLiveData(acceptInviteService.accepted$);
|
||||
const loading = useLiveData(acceptInviteService.loading$);
|
||||
@@ -29,28 +31,32 @@ const AcceptInvite = ({ inviteId }: { inviteId: string }) => {
|
||||
jumpToPage(inviteInfo.workspace.id, 'all', RouteLogic.REPLACE);
|
||||
}, [jumpToPage, inviteInfo]);
|
||||
|
||||
useEffect(() => {
|
||||
acceptInviteService.revalidate({
|
||||
inviteId,
|
||||
});
|
||||
}, [acceptInviteService, inviteId]);
|
||||
const onOpenAffine = useCallback(() => {
|
||||
navigateHelper.jumpToIndex();
|
||||
}, [navigateHelper]);
|
||||
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
acceptInviteService.revalidate({
|
||||
inviteId: targetInviteId,
|
||||
});
|
||||
}, [acceptInviteService, targetInviteId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (error && inviteId === targetInviteId) {
|
||||
const err = UserFriendlyError.fromAnyError(error);
|
||||
if (err.name === ErrorNames.ALREADY_IN_SPACE) {
|
||||
return navigateHelper.jumpToIndex();
|
||||
}
|
||||
}
|
||||
}, [error, navigateHelper]);
|
||||
}, [error, inviteId, navigateHelper, targetInviteId]);
|
||||
|
||||
if (loading) {
|
||||
if (loading || inviteId !== targetInviteId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!inviteInfo) {
|
||||
// if invite is expired
|
||||
return <Navigate to="/expired" />;
|
||||
return <ExpiredPage onOpenAffine={onOpenAffine} />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
@@ -66,7 +72,7 @@ const AcceptInvite = ({ inviteId }: { inviteId: string }) => {
|
||||
);
|
||||
} else {
|
||||
// invite is expired
|
||||
return <Navigate to="/expired" />;
|
||||
return <ExpiredPage onOpenAffine={onOpenAffine} />;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ export class AcceptInviteService extends Service {
|
||||
) {
|
||||
super();
|
||||
}
|
||||
inviteId$ = new LiveData<string | undefined>(undefined);
|
||||
inviteInfo$ = new LiveData<InviteInfo | undefined>(undefined);
|
||||
accepted$ = new LiveData<boolean>(false);
|
||||
loading$ = new LiveData(false);
|
||||
@@ -61,6 +62,7 @@ export class AcceptInviteService extends Service {
|
||||
}),
|
||||
catchErrorInto(this.error$),
|
||||
onStart(() => {
|
||||
this.inviteId$.setValue(inviteId);
|
||||
this.loading$.setValue(true);
|
||||
this.inviteInfo$.setValue(undefined);
|
||||
this.accepted$.setValue(false);
|
||||
|
||||
Reference in New Issue
Block a user