feat(#93): optimiser l’affichage Parents/AM avec modale de détails
Intègre un bandeau unique (onglets à gauche, recherche/filtre en pilule, bouton Ajouter à droite) et compacte les cartes Parents/AM avec ouverture d’une modale complète sur Modifier (croix, actions Modifier/Supprimer). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/parent_model.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_list_header.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_detail_modal.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_list_state.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
|
||||
class ParentManagementWidget extends StatefulWidget {
|
||||
const ParentManagementWidget({super.key});
|
||||
final String searchQuery;
|
||||
final String? statusFilter;
|
||||
|
||||
const ParentManagementWidget({
|
||||
super.key,
|
||||
required this.searchQuery,
|
||||
this.statusFilter,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ParentManagementWidget> createState() => _ParentManagementWidgetState();
|
||||
@@ -16,23 +23,15 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
List<ParentModel> _parents = [];
|
||||
List<ParentModel> _filteredParents = [];
|
||||
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
String? _selectedStatus;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadParents();
|
||||
_searchController.addListener(_filter);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
void dispose() => super.dispose();
|
||||
|
||||
Future<void> _loadParents() async {
|
||||
setState(() {
|
||||
@@ -44,7 +43,6 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_parents = list;
|
||||
_filter(); // Apply initial filter (if any)
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -56,70 +54,44 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
void _filter() {
|
||||
final query = _searchController.text.toLowerCase();
|
||||
setState(() {
|
||||
_filteredParents = _parents.where((p) {
|
||||
final matchesName = p.user.fullName.toLowerCase().contains(query) ||
|
||||
p.user.email.toLowerCase().contains(query);
|
||||
final matchesStatus =
|
||||
_selectedStatus == null || p.user.statut == _selectedStatus;
|
||||
|
||||
return matchesName && matchesStatus;
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = widget.searchQuery.toLowerCase();
|
||||
final filteredParents = _parents.where((p) {
|
||||
final matchesName = p.user.fullName.toLowerCase().contains(query) ||
|
||||
p.user.email.toLowerCase().contains(query);
|
||||
final matchesStatus =
|
||||
widget.statusFilter == null || p.user.statut == widget.statusFilter;
|
||||
return matchesName && matchesStatus;
|
||||
}).toList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AdminListHeader(
|
||||
searchController: _searchController,
|
||||
searchHint: 'Rechercher un parent...',
|
||||
filters: _buildFilters(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
AdminListState(
|
||||
isLoading: _isLoading,
|
||||
error: _error,
|
||||
isEmpty: _filteredParents.isEmpty,
|
||||
isEmpty: filteredParents.isEmpty,
|
||||
emptyMessage: 'Aucun parent trouvé.',
|
||||
list: ListView.builder(
|
||||
itemCount: _filteredParents.length,
|
||||
itemCount: filteredParents.length,
|
||||
itemBuilder: (context, index) {
|
||||
final parent = _filteredParents[index];
|
||||
final parent = filteredParents[index];
|
||||
return AdminUserCard(
|
||||
title: parent.user.fullName,
|
||||
avatarUrl: parent.user.photoUrl,
|
||||
subtitleLines: [
|
||||
parent.user.email,
|
||||
'Statut : ${_displayStatus(parent.user.statut)}',
|
||||
'Enfants : ${parent.childrenCount}',
|
||||
'Statut : ${_displayStatus(parent.user.statut)} | Enfants : ${parent.childrenCount}',
|
||||
],
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.visibility),
|
||||
tooltip: 'Voir dossier',
|
||||
onPressed: () {
|
||||
// TODO: Voir le statut du dossier
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
tooltip: 'Modifier',
|
||||
onPressed: () {
|
||||
// TODO: Modifier parent
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
tooltip: 'Supprimer',
|
||||
onPressed: () {
|
||||
// TODO: Supprimer compte
|
||||
_openParentDetails(parent);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -132,38 +104,6 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilters() {
|
||||
return SizedBox(
|
||||
width: 240,
|
||||
child: DropdownButtonFormField<String?>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut',
|
||||
border: OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
value: _selectedStatus,
|
||||
items: const [
|
||||
DropdownMenuItem<String?>(value: null, child: Text('Tous')),
|
||||
DropdownMenuItem<String?>(value: 'actif', child: Text('Actif')),
|
||||
DropdownMenuItem<String?>(
|
||||
value: 'en_attente',
|
||||
child: Text('En attente'),
|
||||
),
|
||||
DropdownMenuItem<String?>(
|
||||
value: 'suspendu',
|
||||
child: Text('Suspendu'),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedStatus = value;
|
||||
});
|
||||
_filter();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _displayStatus(String? status) {
|
||||
switch (status) {
|
||||
case 'actif':
|
||||
@@ -176,4 +116,49 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
return 'Inconnu';
|
||||
}
|
||||
}
|
||||
|
||||
void _openParentDetails(ParentModel parent) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AdminDetailModal(
|
||||
title: parent.user.fullName.isEmpty ? 'Parent' : parent.user.fullName,
|
||||
subtitle: parent.user.email,
|
||||
fields: [
|
||||
AdminDetailField(label: 'ID', value: _v(parent.user.id)),
|
||||
AdminDetailField(
|
||||
label: 'Statut',
|
||||
value: _displayStatus(parent.user.statut),
|
||||
),
|
||||
AdminDetailField(
|
||||
label: 'Telephone',
|
||||
value: _v(parent.user.telephone),
|
||||
),
|
||||
AdminDetailField(label: 'Adresse', value: _v(parent.user.adresse)),
|
||||
AdminDetailField(label: 'Ville', value: _v(parent.user.ville)),
|
||||
AdminDetailField(
|
||||
label: 'Code postal',
|
||||
value: _v(parent.user.codePostal),
|
||||
),
|
||||
AdminDetailField(
|
||||
label: 'Nombre d\'enfants',
|
||||
value: parent.childrenCount.toString(),
|
||||
),
|
||||
],
|
||||
onEdit: () {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(this.context).showSnackBar(
|
||||
const SnackBar(content: Text('Action Modifier a implementer')),
|
||||
);
|
||||
},
|
||||
onDelete: () {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(this.context).showSnackBar(
|
||||
const SnackBar(content: Text('Action Supprimer a implementer')),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _v(String? value) => (value == null || value.isEmpty) ? '-' : value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user