From a798b037db53a051137bdf305e2b1838eb454da4 Mon Sep 17 00:00:00 2001 From: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:10:06 +0200 Subject: [PATCH] fix: add back invitation success toast (#5875) --- .../members/workspace_member_page.dart | 61 ++++++++++++++++++- frontend/resources/translations/en.json | 2 + 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/members/workspace_member_page.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/members/workspace_member_page.dart index c5f27a1d9c..1cbe2fa1a4 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/members/workspace_member_page.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/members/workspace_member_page.dart @@ -10,6 +10,7 @@ import 'package:appflowy/workspace/presentation/settings/shared/settings_categor import 'package:appflowy/workspace/presentation/settings/widgets/members/workspace_member_bloc.dart'; import 'package:appflowy/workspace/presentation/widgets/dialogs.dart'; import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart'; +import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart'; import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; @@ -35,7 +36,8 @@ class WorkspaceMembersPage extends StatelessWidget { return BlocProvider( create: (context) => WorkspaceMemberBloc(userProfile: userProfile) ..add(const WorkspaceMemberEvent.initial()), - child: BlocBuilder( + child: BlocConsumer( + listener: _showResultDialog, builder: (context, state) { return SettingsBody( title: LocaleKeys.settings_appearance_members_title.tr(), @@ -160,6 +162,63 @@ class WorkspaceMembersPage extends StatelessWidget { return const SizedBox.shrink(); } + + void _showResultDialog(BuildContext context, WorkspaceMemberState state) { + final actionResult = state.actionResult; + if (actionResult == null) { + return; + } + + final actionType = actionResult.actionType; + final result = actionResult.result; + + // only show the result dialog when the action is WorkspaceMemberActionType.add + if (actionType == WorkspaceMemberActionType.add) { + result.fold( + (s) { + showSnackBarMessage( + context, + LocaleKeys.settings_appearance_members_addMemberSuccess.tr(), + ); + }, + (f) { + Log.error('add workspace member failed: $f'); + final message = f.code == ErrorCode.WorkspaceMemberLimitExceeded + ? LocaleKeys.settings_appearance_members_memberLimitExceeded.tr() + : LocaleKeys.settings_appearance_members_failedToAddMember.tr(); + showDialog( + context: context, + builder: (context) => NavigatorOkCancelDialog(message: message), + ); + }, + ); + } else if (actionType == WorkspaceMemberActionType.invite) { + result.fold( + (s) { + showSnackBarMessage( + context, + LocaleKeys.settings_appearance_members_inviteMemberSuccess.tr(), + ); + }, + (f) { + Log.error('invite workspace member failed: $f'); + final message = f.code == ErrorCode.WorkspaceMemberLimitExceeded + ? LocaleKeys.settings_appearance_members_inviteFailedMemberLimit + .tr() + : LocaleKeys.settings_appearance_members_failedToInviteMember + .tr(); + showConfirmDialog( + context: context, + title: LocaleKeys + .settings_appearance_members_inviteFailedDialogTitle + .tr(), + description: message, + confirmLabel: LocaleKeys.button_ok.tr(), + ); + }, + ); + } + } } class _InviteMember extends StatefulWidget { diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json index 09eb30e7e2..84efac4f50 100644 --- a/frontend/resources/translations/en.json +++ b/frontend/resources/translations/en.json @@ -1096,6 +1096,8 @@ "one": "{} member", "other": "{} members" }, + "inviteFailedDialogTitle": "Failed to send invite", + "inviteFailedMemberLimit": "Member limit has been reached, please upgrade to invite more members.", "memberLimitExceeded": "Member limit reached, to invite more members, please ", "memberLimitExceededUpgrade": "upgrade", "memberLimitExceededPro": "Member limit reached, if you require more members contact ",