From 2c9dc5199c910142119b856fd0daf176977ae739 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 Apr 2020 14:04:47 +0200 Subject: [PATCH] Can cancel membership request --- lib/helpers/groups_helper.dart | 4 +++ lib/ui/widgets/group_membership_widget.dart | 27 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/helpers/groups_helper.dart b/lib/helpers/groups_helper.dart index c050f6e..58ece46 100644 --- a/lib/helpers/groups_helper.dart +++ b/lib/helpers/groups_helper.dart @@ -114,6 +114,10 @@ class GroupsHelper { Future cancelRequest(int groupID) async => _simpleMembershipRequest(groupID, "groups/cancel_request"); + /// Send a new membership request + Future sendRequest(int groupID) async => + _simpleMembershipRequest(groupID, "groups/send_request"); + /// Turn an API entry into a group object Group _getGroupFromAPI(Map map) { return Group( diff --git a/lib/ui/widgets/group_membership_widget.dart b/lib/ui/widgets/group_membership_widget.dart index e8cb516..f0b82fa 100644 --- a/lib/ui/widgets/group_membership_widget.dart +++ b/lib/ui/widgets/group_membership_widget.dart @@ -49,8 +49,7 @@ class _GroupMembershipWidgetState extends SafeState { return _buildPendingState(); case GroupMembershipLevel.VISITOR: - // TODO: Handle this case. - break; + return _buildVisitorState(); } } @@ -79,4 +78,28 @@ class _GroupMembershipWidgetState extends SafeState { if (this.widget.onUpdated != null) this.widget.onUpdated(); } } + + /// Build visitor state + Widget _buildVisitorState() { + return RichText( + text: TextSpan( + text: tr("Request membership"), + style: TextStyle(color: Colors.blue), + recognizer: TapGestureRecognizer() + ..onTap = () => _requestMembership()), + ); + } + + /// Create new membership request + void _requestMembership() async { + if (!await GroupsHelper().sendRequest(_id)) + showSimpleSnack(context, tr("Could not send your membership request!")); + else { + // Refresh state + group.membershipLevel = GroupMembershipLevel.PENDING; + this.setState(() {}); + + if (this.widget.onUpdated != null) this.widget.onUpdated(); + } + } }