diff --git a/backend/src/controllers/memberController.js b/backend/src/controllers/memberController.js index b9a72f4..a84a5a8 100644 --- a/backend/src/controllers/memberController.js +++ b/backend/src/controllers/memberController.js @@ -133,7 +133,13 @@ const removeMemberFromGroup = async (req, res) => { // Find the membership const groupMember = await GroupMember.findOne({ - where: { group_id: groupId, user_id: memberId } + where: { group_id: groupId, user_id: memberId }, + include: [ + { + model: User, + attributes: ['id', 'full_name', 'mobile_number'] + } + ] }); if (!groupMember) { @@ -143,12 +149,20 @@ const removeMemberFromGroup = async (req, res) => { }); } - // Remove member + const memberName = groupMember.User?.full_name || 'Member'; + + // Remove member from THIS group only (user still exists in system) await groupMember.update({ status: 'removed' }); res.json({ success: true, - message: 'Member removed successfully' + message: `${memberName} removed from this group. They can still be added to other groups.`, + data: { + removedFromGroup: true, + userStillExists: true, + canBeAddedToOtherGroups: true, + memberName: memberName + } }); } catch (error) { console.error('Remove member error:', error); diff --git a/luckychit/lib/interfaces/manager/group_details_page.dart b/luckychit/lib/interfaces/manager/group_details_page.dart index c63013f..0147cf2 100644 --- a/luckychit/lib/interfaces/manager/group_details_page.dart +++ b/luckychit/lib/interfaces/manager/group_details_page.dart @@ -97,10 +97,10 @@ class _GroupDetailsPageState extends State with SingleTickerPr elevation: 0, actions: [ // Actions menu - always visible - PopupMenuButton( + PopupMenuButton( icon: Icon(Icons.more_vert, size: 24.w, color: Colors.grey.shade700), tooltip: 'More Options', - onSelected: (value) { + onSelected: (value) { if (value == 'edit_group') { _editGroup(); } else if (value == 'delete_group') { @@ -147,26 +147,26 @@ class _GroupDetailsPageState extends State with SingleTickerPr ], // Add members options (if not full) if (canAddMembers) ...[ - PopupMenuItem( - value: 'select', - child: Row( - children: [ - Icon(Icons.people_alt, color: Colors.blue.shade600), + PopupMenuItem( + value: 'select', + child: Row( + children: [ + Icon(Icons.people_alt, color: Colors.blue.shade600), SizedBox(width: 12.w), - const Text('Select Members'), - ], - ), + const Text('Select Members'), + ], ), - PopupMenuItem( - value: 'add_user', - child: Row( - children: [ - Icon(Icons.person_add, color: Colors.green.shade600), + ), + PopupMenuItem( + value: 'add_user', + child: Row( + children: [ + Icon(Icons.person_add, color: Colors.green.shade600), SizedBox(width: 12.w), - const Text('Add New User'), - ], - ), + const Text('Add New User'), + ], ), + ), const PopupMenuDivider(), ], // Backfill options (always available) @@ -1090,12 +1090,12 @@ class _GroupDetailsPageState extends State with SingleTickerPr ), Column( children: [ - Text( - '${draw.drawDate.day}/${draw.drawDate.month}/${draw.drawDate.year}', - style: TextStyle( - fontSize: 12.sp, - color: Colors.grey.shade600, - ), + Text( + '${draw.drawDate.day}/${draw.drawDate.month}/${draw.drawDate.year}', + style: TextStyle( + fontSize: 12.sp, + color: Colors.grey.shade600, + ), ), SizedBox(height: 8.h), // Action Buttons @@ -1540,9 +1540,9 @@ class _GroupDetailsPageState extends State with SingleTickerPr ], ), child: Center( - child: Text( + child: Text( '#${member.memberNumber}', - style: TextStyle( + style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18.sp, @@ -1559,12 +1559,12 @@ class _GroupDetailsPageState extends State with SingleTickerPr children: [ Expanded( child: Text( - member.user?.fullName ?? 'Unknown Member', - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 16.sp, - color: Colors.black87, - ), + member.user?.fullName ?? 'Unknown Member', + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.sp, + color: Colors.black87, + ), ), ), Container( @@ -2174,8 +2174,63 @@ class _GroupDetailsPageState extends State with SingleTickerPr showDialog( context: context, builder: (context) => AlertDialog( - title: const Text('Remove Member'), - content: Text('Are you sure you want to remove ${member.user?.fullName ?? 'this member'} from the group?'), + title: Row( + children: [ + Icon(Icons.remove_circle_outline, color: Colors.orange.shade700), + SizedBox(width: 8.w), + const Text('Remove Member from Group'), + ], + ), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Are you sure you want to remove ${member.user?.fullName ?? 'this member'} (Member #${member.memberNumber}) from this group?', + style: TextStyle(fontSize: 15.sp), + ), + SizedBox(height: 16.h), + Container( + padding: EdgeInsets.all(12.w), + decoration: BoxDecoration( + color: Colors.blue.shade50, + borderRadius: BorderRadius.circular(8.r), + border: Border.all(color: Colors.blue.shade200), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Icon(Icons.info_outline, size: 16.w, color: Colors.blue.shade700), + SizedBox(width: 6.w), + Text( + 'Important:', + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.blue.shade900, + fontSize: 13.sp, + ), + ), + ], + ), + SizedBox(height: 6.h), + Text( + '• Member is only removed from THIS group\n' + '• Their account remains active\n' + '• They can still be added to other groups\n' + '• Their user data is preserved', + style: TextStyle( + fontSize: 12.sp, + color: Colors.blue.shade900, + height: 1.4, + ), + ), + ], + ), + ), + ], + ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), @@ -2184,16 +2239,22 @@ class _GroupDetailsPageState extends State with SingleTickerPr ElevatedButton( onPressed: () async { Navigator.of(context).pop(); - final success = await _service.removeMemberFromGroup(widget.group.id, member.id); + final success = await _service.removeMemberFromGroup(widget.group.id, member.userId); if (success) { - Get.snackbar('Success', 'Member removed successfully'); + Get.snackbar( + 'Member Removed from Group', + '${member.user?.fullName ?? 'Member'} removed from ${widget.group.name}. They can still be added to other groups.', + backgroundColor: Colors.green, + colorText: Colors.white, + duration: const Duration(seconds: 4), + ); } }, style: ElevatedButton.styleFrom( - backgroundColor: Colors.red, + backgroundColor: Colors.orange.shade600, foregroundColor: Colors.white, ), - child: const Text('Remove'), + child: const Text('Remove from Group'), ), ], ),