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(); + } + } }