From fae18f0abd29b2719102a6f1b360b5e29c6bc124 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 25 Apr 2021 17:34:20 +0200 Subject: [PATCH] Can respond to membership requests from members screen --- .../ui/screens/forez_directory_screen.dart | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/forez/ui/screens/forez_directory_screen.dart b/lib/forez/ui/screens/forez_directory_screen.dart index 4c9a0da..f3969bb 100644 --- a/lib/forez/ui/screens/forez_directory_screen.dart +++ b/lib/forez/ui/screens/forez_directory_screen.dart @@ -19,7 +19,12 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert -enum _PopupMenuActions { PRIVATE_CONVERSATION, CANCEL_INVITATION } +enum _PopupMenuActions { + PRIVATE_CONVERSATION, + CANCEL_INVITATION, + ACCEPT_REQUEST, + REJECT_REQUEST +} class ForezDirectoryScreen extends StatefulWidget { @override @@ -65,6 +70,16 @@ class _ForezDirectoryScreenState extends State { await GroupsHelper.cancelInvitation(forezGroup.id, user.id); _key.currentState.refresh(); break; + + case _PopupMenuActions.ACCEPT_REQUEST: + await GroupsHelper.respondRequest(forezGroup.id, user.id, true); + _key.currentState.refresh(); + break; + + case _PopupMenuActions.REJECT_REQUEST: + await GroupsHelper.respondRequest(forezGroup.id, user.id, false); + _key.currentState.refresh(); + break; } } catch (e, s) { logError(e, s); @@ -90,12 +105,40 @@ class _ForezMemberTile extends StatelessWidget { leading: AccountImageWidget(user: user), title: Text(user.fullName), subtitle: Text(member.membershipText), - trailing: user.id == userID() - ? null - : PopupMenuButton( - itemBuilder: (c) => popupMenuItems, - onSelected: (a) => selectedAction(a, user), - ), + trailing: member.level == GroupMembershipLevel.PENDING + ? _buildRequestedButton() + : _buildPopupMenuButton(), + ); + + Widget _buildPopupMenuButton() => user.id == userID() + ? null + : PopupMenuButton( + itemBuilder: (c) => popupMenuItems, + onSelected: (a) => selectedAction(a, user), + ); + + Widget _buildRequestedButton() => IntrinsicWidth( + child: Row( + children: [ + ElevatedButton( + onPressed: () => + selectedAction(_PopupMenuActions.ACCEPT_REQUEST, user), + child: Icon(Icons.check), + style: ButtonStyle( + visualDensity: VisualDensity.compact, + backgroundColor: MaterialStateProperty.all(Colors.green)), + ), + SizedBox(width: 5), + OutlinedButton( + onPressed: () => + selectedAction(_PopupMenuActions.REJECT_REQUEST, user), + child: Icon(Icons.close), + style: ButtonStyle( + visualDensity: VisualDensity.compact, + foregroundColor: MaterialStateProperty.all(Colors.redAccent)), + ), + ], + ), ); List> get popupMenuItems => [