fix: add back invitation success toast (#5875)

This commit is contained in:
Mathias Mogensen 2024-08-06 10:10:06 +02:00 committed by GitHub
parent 5fbaf664ba
commit a798b037db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 62 additions and 1 deletions

View File

@ -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<WorkspaceMemberBloc>(
create: (context) => WorkspaceMemberBloc(userProfile: userProfile)
..add(const WorkspaceMemberEvent.initial()),
child: BlocBuilder<WorkspaceMemberBloc, WorkspaceMemberState>(
child: BlocConsumer<WorkspaceMemberBloc, WorkspaceMemberState>(
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 {

View File

@ -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 ",