fix(core): handle errors on the invite page (#9167)

close AF-1975
This commit is contained in:
JimmFly
2024-12-16 03:30:19 +00:00
parent aaaea8918f
commit 8eafc057fa
3 changed files with 17 additions and 4 deletions
@@ -23,7 +23,7 @@ export const Component = () => {
return ( return (
<AuthPageContainer <AuthPageContainer
title={t['com.affine.expired.page.title']()} title={t['com.affine.expired.page.title']()}
subtitle={t['com.affine.expired.page.subtitle']()} subtitle={t['com.affine.expired.page.new-subtitle']()}
> >
<Button variant="primary" size="large" onClick={onOpenAffine}> <Button variant="primary" size="large" onClick={onOpenAffine}>
{t['com.affine.auth.open.affine']()} {t['com.affine.auth.open.affine']()}
@@ -2,7 +2,9 @@ import { AcceptInvitePage } from '@affine/component/member-components';
import type { GetInviteInfoQuery } from '@affine/graphql'; import type { GetInviteInfoQuery } from '@affine/graphql';
import { import {
acceptInviteByInviteIdMutation, acceptInviteByInviteIdMutation,
ErrorNames,
getInviteInfoQuery, getInviteInfoQuery,
UserFriendlyError,
} from '@affine/graphql'; } from '@affine/graphql';
import { useLiveData, useService } from '@toeverything/infra'; import { useLiveData, useService } from '@toeverything/infra';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
@@ -103,9 +105,19 @@ export const Middle = () => {
inviteInfo: res.getInviteInfo, inviteInfo: res.getInviteInfo,
}); });
return; return;
})().catch(err => { })().catch(error => {
// TODO: handle error const userFriendlyError = UserFriendlyError.fromAnyError(error);
console.error(err); console.error(userFriendlyError);
if (userFriendlyError.name === ErrorNames.ALREADY_IN_SPACE) {
return navigateHelper.jumpToIndex();
}
if (
userFriendlyError.name === ErrorNames.USER_NOT_FOUND ||
userFriendlyError.name === ErrorNames.SPACE_OWNER_NOT_FOUND
) {
return navigateHelper.jumpToExpired();
}
return navigateHelper.jumpTo404();
}); });
}, [graphqlService, navigateHelper, params.inviteId]); }, [graphqlService, navigateHelper, params.inviteId]);
@@ -487,6 +487,7 @@
"com.affine.error.retry": "Refresh", "com.affine.error.retry": "Refresh",
"com.affine.error.unexpected-error.title": "Something is wrong...", "com.affine.error.unexpected-error.title": "Something is wrong...",
"com.affine.expired.page.subtitle": "Please request a new reset password link.", "com.affine.expired.page.subtitle": "Please request a new reset password link.",
"com.affine.expired.page.new-subtitle": "Please request a new link.",
"com.affine.expired.page.title": "This link has expired...", "com.affine.expired.page.title": "This link has expired...",
"com.affine.export.error.message": "Please try it again later.", "com.affine.export.error.message": "Please try it again later.",
"com.affine.export.error.title": "Export failed due to an unexpected error", "com.affine.export.error.title": "Export failed due to an unexpected error",