refactor(#93): homogénéiser la présentation des onglets admin
Uniformise les 4 onglets de gestion admin avec des composants UI partagés (header, états de liste, carte utilisateur) pour garantir une expérience cohérente sans changement backend. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
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_list_state.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
|
||||
class ParentManagementWidget extends StatefulWidget {
|
||||
const ParentManagementWidget({super.key});
|
||||
@@ -59,14 +62,9 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
_filteredParents = _parents.where((p) {
|
||||
final matchesName = p.user.fullName.toLowerCase().contains(query) ||
|
||||
p.user.email.toLowerCase().contains(query);
|
||||
final matchesStatus = _selectedStatus == null ||
|
||||
_selectedStatus == 'Tous' ||
|
||||
(p.user.statut?.toLowerCase() == _selectedStatus?.toLowerCase());
|
||||
|
||||
// Mapping simple pour le statut affiché vs backend
|
||||
// Backend: en_attente, actif, suspendu
|
||||
// Dropdown: En attente, Actif, Suspendu
|
||||
|
||||
final matchesStatus =
|
||||
_selectedStatus == null || p.user.statut == _selectedStatus;
|
||||
|
||||
return matchesName && matchesStatus;
|
||||
}).toList();
|
||||
});
|
||||
@@ -79,113 +77,103 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSearchSection(),
|
||||
AdminListHeader(
|
||||
searchController: _searchController,
|
||||
searchHint: 'Rechercher un parent...',
|
||||
filters: _buildFilters(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_isLoading)
|
||||
const Center(child: CircularProgressIndicator())
|
||||
else if (_error != null)
|
||||
Center(child: Text('Erreur: $_error', style: const TextStyle(color: Colors.red)))
|
||||
else if (_filteredParents.isEmpty)
|
||||
const Center(child: Text("Aucun parent trouvé."))
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _filteredParents.length,
|
||||
itemBuilder: (context, index) {
|
||||
final parent = _filteredParents[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundImage: parent.user.photoUrl != null
|
||||
? NetworkImage(parent.user.photoUrl!)
|
||||
: null,
|
||||
child: parent.user.photoUrl == null
|
||||
? const Icon(Icons.person)
|
||||
: null,
|
||||
),
|
||||
title: Text(parent.user.fullName.isNotEmpty
|
||||
? parent.user.fullName
|
||||
: 'Sans nom'),
|
||||
subtitle: Text(
|
||||
"${parent.user.email}\nStatut : ${parent.user.statut ?? 'Inconnu'} | Enfants : ${parent.childrenCount}",
|
||||
),
|
||||
isThreeLine: true,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
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
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
AdminListState(
|
||||
isLoading: _isLoading,
|
||||
error: _error,
|
||||
isEmpty: _filteredParents.isEmpty,
|
||||
emptyMessage: 'Aucun parent trouvé.',
|
||||
list: ListView.builder(
|
||||
itemCount: _filteredParents.length,
|
||||
itemBuilder: (context, 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}',
|
||||
],
|
||||
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
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchSection() {
|
||||
return Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 220,
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Nom du parent",
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.search),
|
||||
),
|
||||
),
|
||||
Widget _buildFilters() {
|
||||
return SizedBox(
|
||||
width: 240,
|
||||
child: DropdownButtonFormField<String?>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut',
|
||||
border: OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
SizedBox(
|
||||
width: 220,
|
||||
child: DropdownButtonFormField<String>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Statut",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
value: _selectedStatus,
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text("Tous")),
|
||||
DropdownMenuItem(value: "actif", child: Text("Actif")),
|
||||
DropdownMenuItem(value: "en_attente", child: Text("En attente")),
|
||||
DropdownMenuItem(value: "suspendu", child: Text("Suspendu")),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedStatus = value;
|
||||
_filter();
|
||||
});
|
||||
},
|
||||
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':
|
||||
return 'Actif';
|
||||
case 'en_attente':
|
||||
return 'En attente';
|
||||
case 'suspendu':
|
||||
return 'Suspendu';
|
||||
default:
|
||||
return 'Inconnu';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user