fixed member remove issues
This commit is contained in:
parent
ced626f9e3
commit
b3f064d48d
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,10 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
actions: [
|
actions: [
|
||||||
// Actions menu - always visible
|
// Actions menu - always visible
|
||||||
PopupMenuButton<String>(
|
PopupMenuButton<String>(
|
||||||
icon: Icon(Icons.more_vert, size: 24.w, color: Colors.grey.shade700),
|
icon: Icon(Icons.more_vert, size: 24.w, color: Colors.grey.shade700),
|
||||||
tooltip: 'More Options',
|
tooltip: 'More Options',
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
if (value == 'edit_group') {
|
if (value == 'edit_group') {
|
||||||
_editGroup();
|
_editGroup();
|
||||||
} else if (value == 'delete_group') {
|
} else if (value == 'delete_group') {
|
||||||
|
|
@ -147,26 +147,26 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
],
|
],
|
||||||
// Add members options (if not full)
|
// Add members options (if not full)
|
||||||
if (canAddMembers) ...[
|
if (canAddMembers) ...[
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'select',
|
value: 'select',
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.people_alt, color: Colors.blue.shade600),
|
Icon(Icons.people_alt, color: Colors.blue.shade600),
|
||||||
SizedBox(width: 12.w),
|
SizedBox(width: 12.w),
|
||||||
const Text('Select Members'),
|
const Text('Select Members'),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
),
|
||||||
value: 'add_user',
|
PopupMenuItem(
|
||||||
child: Row(
|
value: 'add_user',
|
||||||
children: [
|
child: Row(
|
||||||
Icon(Icons.person_add, color: Colors.green.shade600),
|
children: [
|
||||||
|
Icon(Icons.person_add, color: Colors.green.shade600),
|
||||||
SizedBox(width: 12.w),
|
SizedBox(width: 12.w),
|
||||||
const Text('Add New User'),
|
const Text('Add New User'),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const PopupMenuDivider(),
|
const PopupMenuDivider(),
|
||||||
],
|
],
|
||||||
// Backfill options (always available)
|
// Backfill options (always available)
|
||||||
|
|
@ -1090,12 +1090,12 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${draw.drawDate.day}/${draw.drawDate.month}/${draw.drawDate.year}',
|
'${draw.drawDate.day}/${draw.drawDate.month}/${draw.drawDate.year}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12.sp,
|
fontSize: 12.sp,
|
||||||
color: Colors.grey.shade600,
|
color: Colors.grey.shade600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 8.h),
|
SizedBox(height: 8.h),
|
||||||
// Action Buttons
|
// Action Buttons
|
||||||
|
|
@ -1540,9 +1540,9 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'#${member.memberNumber}',
|
'#${member.memberNumber}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 18.sp,
|
fontSize: 18.sp,
|
||||||
|
|
@ -1559,12 +1559,12 @@ class _GroupDetailsPageState extends State<GroupDetailsPage> with SingleTickerPr
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
member.user?.fullName ?? 'Unknown Member',
|
member.user?.fullName ?? 'Unknown Member',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 16.sp,
|
fontSize: 16.sp,
|
||||||
color: Colors.black87,
|
color: Colors.black87,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
|
|
@ -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'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue