fixed member remove issues

This commit is contained in:
Deep Koluguri 2025-11-06 14:56:04 -05:00
parent ced626f9e3
commit b3f064d48d
2 changed files with 116 additions and 41 deletions

View File

@ -133,7 +133,13 @@ const removeMemberFromGroup = async (req, res) => {
// Find the membership // Find the membership
const groupMember = await GroupMember.findOne({ 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) { 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' }); await groupMember.update({ status: 'removed' });
res.json({ res.json({
success: true, 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) { } catch (error) {
console.error('Remove member error:', error); console.error('Remove member error:', error);

View File

@ -2174,8 +2174,63 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: const Text('Remove Member'), title: Row(
content: Text('Are you sure you want to remove ${member.user?.fullName ?? 'this member'} from the group?'), 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: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
@ -2184,16 +2239,22 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: () async {
Navigator.of(context).pop(); 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) { 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( style: ElevatedButton.styleFrom(
backgroundColor: Colors.red, backgroundColor: Colors.orange.shade600,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), ),
child: const Text('Remove'), child: const Text('Remove from Group'),
), ),
], ],
), ),