mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: support inviting members (#5118)
* feat: support inviting members * chore: update memeber error log * feat: invite as member
This commit is contained in:
parent
9a8109f5f8
commit
4d860cc404
@ -177,6 +177,20 @@ class UserBackendService {
|
||||
return UserEventAddWorkspaceMember(data).send();
|
||||
}
|
||||
|
||||
Future<FlowyResult<void, FlowyError>> inviteWorkspaceMember(
|
||||
String workspaceId,
|
||||
String email, {
|
||||
AFRolePB? role,
|
||||
}) async {
|
||||
final data = WorkspaceMemberInvitationPB()
|
||||
..workspaceId = workspaceId
|
||||
..inviteeEmail = email;
|
||||
if (role != null) {
|
||||
data.role = role;
|
||||
}
|
||||
return UserEventInviteWorkspaceMember(data).send();
|
||||
}
|
||||
|
||||
Future<FlowyResult<void, FlowyError>> removeWorkspaceMember(
|
||||
String workspaceId,
|
||||
String email,
|
||||
|
@ -91,6 +91,21 @@ class WorkspaceMemberBloc
|
||||
add(const WorkspaceMemberEvent.getWorkspaceMembers());
|
||||
});
|
||||
},
|
||||
inviteWorkspaceMember: (email) async {
|
||||
final result = await _userBackendService.inviteWorkspaceMember(
|
||||
_workspaceId,
|
||||
email,
|
||||
role: AFRolePB.Member,
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
actionResult: WorkspaceMemberActionResult(
|
||||
actionType: WorkspaceMemberActionType.invite,
|
||||
result: result,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
removeWorkspaceMember: (email) async {
|
||||
final result = await _userBackendService.removeWorkspaceMember(
|
||||
_workspaceId,
|
||||
@ -186,6 +201,8 @@ class WorkspaceMemberEvent with _$WorkspaceMemberEvent {
|
||||
GetWorkspaceMembers;
|
||||
const factory WorkspaceMemberEvent.addWorkspaceMember(String email) =
|
||||
AddWorkspaceMember;
|
||||
const factory WorkspaceMemberEvent.inviteWorkspaceMember(String email) =
|
||||
InviteWorkspaceMember;
|
||||
const factory WorkspaceMemberEvent.removeWorkspaceMember(String email) =
|
||||
RemoveWorkspaceMember;
|
||||
const factory WorkspaceMemberEvent.updateWorkspaceMember(
|
||||
@ -197,6 +214,9 @@ class WorkspaceMemberEvent with _$WorkspaceMemberEvent {
|
||||
enum WorkspaceMemberActionType {
|
||||
none,
|
||||
get,
|
||||
// this event will send an invitation to the member
|
||||
invite,
|
||||
// this event will add the member without sending an invitation
|
||||
add,
|
||||
remove,
|
||||
updateRole,
|
||||
|
@ -75,6 +75,7 @@ class WorkspaceMembersPage extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
(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();
|
||||
@ -84,6 +85,26 @@ class WorkspaceMembersPage extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
);
|
||||
} 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_memberLimitExceeded.tr()
|
||||
: LocaleKeys.settings_appearance_members_failedToInviteMember
|
||||
.tr();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => NavigatorOkCancelDialog(message: message),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
result.onFailure((f) {
|
||||
@ -193,7 +214,7 @@ class _InviteMemberState extends State<_InviteMember> {
|
||||
}
|
||||
context
|
||||
.read<WorkspaceMemberBloc>()
|
||||
.add(WorkspaceMemberEvent.addWorkspaceMember(email));
|
||||
.add(WorkspaceMemberEvent.inviteWorkspaceMember(email));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,7 +500,9 @@
|
||||
"failedToAddMember": "Failed to add member",
|
||||
"addMemberSuccess": "Member added successfully",
|
||||
"removeMember": "Remove Member",
|
||||
"areYouSureToRemoveMember": "Are you sure you want to remove this member?"
|
||||
"areYouSureToRemoveMember": "Are you sure you want to remove this member?",
|
||||
"inviteMemberSuccess": "The invitation has been sent successfully",
|
||||
"failedToInviteMember": "Failed to invite member"
|
||||
}
|
||||
},
|
||||
"files": {
|
||||
|
Loading…
Reference in New Issue
Block a user