From b0b7534599c555a9dfa6848f9040482a46957d8f Mon Sep 17 00:00:00 2001 From: Flrande <1978616327@qq.com> Date: Tue, 1 Apr 2025 04:15:01 +0000 Subject: [PATCH] fix(editor): improve error message in mention (#11309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close [BS-2972](https://linear.app/affine-design/issue/BS-2972/邀请了无权限阅读的用户时,报错信息展示不正确) Close [BS-2973](https://linear.app/affine-design/issue/BS-2973/也没有区分邀请人是否有邀请权限,并如设计稿给出邀请提示) --- .../modules/at-menu-config/services/index.ts | 41 ++++++++++++++++++- packages/frontend/i18n/src/i18n.gen.ts | 18 ++++++++ packages/frontend/i18n/src/resources/en.json | 4 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/modules/at-menu-config/services/index.ts b/packages/frontend/core/src/modules/at-menu-config/services/index.ts index d4dabe435..ced1c8aea 100644 --- a/packages/frontend/core/src/modules/at-menu-config/services/index.ts +++ b/packages/frontend/core/src/modules/at-menu-config/services/index.ts @@ -1,6 +1,6 @@ import { notify } from '@affine/component'; import { UserFriendlyError } from '@affine/error'; -import { type DocMode as GraphqlDocMode } from '@affine/graphql'; +import { type DocMode as GraphqlDocMode, ErrorNames } from '@affine/graphql'; import { I18n, i18nTime } from '@affine/i18n'; import track from '@affine/track'; import { @@ -432,6 +432,45 @@ export class AtMenuConfigService extends Service { }) .catch(error => { const err = UserFriendlyError.fromAny(error); + + const canUserManage = this.guardService.can$( + 'Workspace_Users_Manage' + ).signal.value; + + if (err.is(ErrorNames.MENTION_USER_DOC_ACCESS_DENIED)) { + if (canUserManage) { + const username = name ?? 'Unknown'; + notify.error({ + title: I18n.t('com.affine.editor.at-menu.access-needed'), + message: I18n[ + 'com.affine.editor.at-menu.access-needed-message' + ]({ + username, + }), + action: { + label: 'Invite', + onClick: () => { + this.dialogService.open('setting', { + activeTab: 'workspace:members', + }); + }, + }, + }); + } else { + notify.error({ + title: I18n.t( + 'com.affine.editor.at-menu.member-not-notified' + ), + message: + I18n[ + 'com.affine.editor.at-menu.member-not-notified-message' + ](), + }); + } + + return; + } + notify.error({ title: I18n[`error.${err.name}`](err.data), }); diff --git a/packages/frontend/i18n/src/i18n.gen.ts b/packages/frontend/i18n/src/i18n.gen.ts index f9dd92cbf..aebe94db2 100644 --- a/packages/frontend/i18n/src/i18n.gen.ts +++ b/packages/frontend/i18n/src/i18n.gen.ts @@ -7031,6 +7031,24 @@ export function useAFFiNEI18N(): { * `Mention Members` */ ["com.affine.editor.at-menu.mention-members"](): string; + /** + * `Member not notified` + */ + ["com.affine.editor.at-menu.member-not-notified"](): string; + /** + * `This member does not have access to this doc, they are not notified.` + */ + ["com.affine.editor.at-menu.member-not-notified-message"](): string; + /** + * `Access needed` + */ + ["com.affine.editor.at-menu.access-needed"](): string; + /** + * `{{username}} does not have access to this doc, do you want to invite and notify them?` + */ + ["com.affine.editor.at-menu.access-needed-message"](options: { + readonly username: string; + }): string; /** * `Show` */ diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.json index d43e2559c..77e8eed3a 100644 --- a/packages/frontend/i18n/src/resources/en.json +++ b/packages/frontend/i18n/src/resources/en.json @@ -1746,6 +1746,10 @@ "com.affine.editor.at-menu.journal": "Journal", "com.affine.editor.at-menu.date-picker": "Select a specific date", "com.affine.editor.at-menu.mention-members": "Mention Members", + "com.affine.editor.at-menu.member-not-notified": "Member not notified", + "com.affine.editor.at-menu.member-not-notified-message": "This member does not have access to this doc, they are not notified.", + "com.affine.editor.at-menu.access-needed": "Access needed", + "com.affine.editor.at-menu.access-needed-message": "{{username}} does not have access to this doc, do you want to invite and notify them?", "com.affine.editor.bi-directional-link-panel.show": "Show", "com.affine.editor.bi-directional-link-panel.hide": "Hide", "com.affine.editor.edgeless-note-header.fold-page-block": "Fold page block",