151 lines
4.9 KiB
Dart
151 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../constant/links.dart';
|
|
import '../../../controller/functions/crud.dart';
|
|
import '../../widgets/snackbar.dart';
|
|
|
|
class PendingAdminsPage extends StatefulWidget {
|
|
const PendingAdminsPage({super.key});
|
|
|
|
@override
|
|
State<PendingAdminsPage> createState() => _PendingAdminsPageState();
|
|
}
|
|
|
|
class _PendingAdminsPageState extends State<PendingAdminsPage> {
|
|
final CRUD _crud = CRUD();
|
|
bool _isLoading = true;
|
|
List _pendingAdmins = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_fetchPendingAdmins();
|
|
}
|
|
|
|
Future<void> _fetchPendingAdmins() async {
|
|
setState(() => _isLoading = true);
|
|
try {
|
|
final response = await _crud.post(
|
|
link: '${AppLink.server}/Admin/auth/list_pending.php',
|
|
);
|
|
if (response != 'failure') {
|
|
setState(() {
|
|
_pendingAdmins = response['message'] ?? [];
|
|
});
|
|
}
|
|
} catch (e) {
|
|
mySnackbarError('فشل في جلب البيانات: $e');
|
|
} finally {
|
|
setState(() => _isLoading = false);
|
|
}
|
|
}
|
|
|
|
Future<void> _handleAction(String adminId, String action) async {
|
|
try {
|
|
final response = await _crud.post(
|
|
link: '${AppLink.server}/Admin/auth/approve_admin.php',
|
|
payload: {
|
|
'admin_id': adminId,
|
|
'action': action,
|
|
},
|
|
);
|
|
if (response != 'failure') {
|
|
mySnackbarSuccess('تم تنفيذ الإجراء بنجاح');
|
|
_fetchPendingAdmins();
|
|
}
|
|
} catch (e) {
|
|
mySnackbarError('حدث خطأ: $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
appBar: AppBar(
|
|
title: const Text('طلبات الانضمام المعلقة', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
backgroundColor: cs.surfaceContainerHighest,
|
|
elevation: 0,
|
|
),
|
|
body: _isLoading
|
|
? Center(child: CircularProgressIndicator(color: cs.primary))
|
|
: _pendingAdmins.isEmpty
|
|
? _buildEmptyState(cs)
|
|
: _buildList(cs),
|
|
);
|
|
}
|
|
|
|
Widget _buildEmptyState(ColorScheme cs) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.person_search_rounded, size: 80, color: cs.outline),
|
|
const SizedBox(height: 16),
|
|
Text('لا توجد طلبات معلقة حالياً', style: TextStyle(color: cs.onSurfaceVariant)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildList(ColorScheme cs) {
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _pendingAdmins.length,
|
|
itemBuilder: (context, index) {
|
|
final admin = _pendingAdmins[index];
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
leading: CircleAvatar(
|
|
backgroundColor: cs.outline,
|
|
child: Icon(Icons.person, color: cs.primary),
|
|
),
|
|
title: Text(admin['name'] ?? 'بدون اسم', style: TextStyle(color: cs.onSurface, fontWeight: FontWeight.bold)),
|
|
subtitle: Text(admin['phone'] ?? 'بدون رقم', style: TextStyle(color: cs.onSurfaceVariant)),
|
|
trailing: Text(
|
|
admin['created_at']?.split(' ')[0] ?? '',
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 12),
|
|
),
|
|
),
|
|
Divider(color: cs.outline, height: 24),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => _handleAction(admin['id'], 'rejected'),
|
|
style: TextButton.styleFrom(foregroundColor: cs.error),
|
|
child: const Text('رفض'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ElevatedButton(
|
|
onPressed: () => _handleAction(admin['id'], 'approved'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: cs.primary,
|
|
foregroundColor: cs.onPrimary,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
child: const Text('موافقة', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|