feat(#35): unifier la modale gestionnaire en création et édition
Branche la modale sur l'action Modifier, supprime l'action dédiée de rattachement relais, ajoute la suppression avec confirmation et sécurise le dropdown relais en édition. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/relais_model.dart';
|
||||
import 'package:p_tits_pas/models/user.dart';
|
||||
import 'package:p_tits_pas/services/relais_service.dart';
|
||||
import 'package:p_tits_pas/screens/administrateurs/creation/gestionnaires_create.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/user_list.dart';
|
||||
@@ -24,7 +23,6 @@ class _GestionnaireManagementWidgetState
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
List<AppUser> _gestionnaires = [];
|
||||
List<RelaisModel> _relais = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -42,17 +40,9 @@ class _GestionnaireManagementWidgetState
|
||||
});
|
||||
try {
|
||||
final gestionnaires = await UserService.getGestionnaires();
|
||||
List<RelaisModel> relais = [];
|
||||
try {
|
||||
relais = await RelaisService.getRelais();
|
||||
} catch (_) {
|
||||
// L'ecran reste utilisable meme si la route Relais n'est pas disponible.
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_gestionnaires = gestionnaires;
|
||||
_relais = relais;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -64,81 +54,16 @@ class _GestionnaireManagementWidgetState
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openRelaisAssignmentDialog(AppUser user) async {
|
||||
String? selectedRelaisId = user.relaisId;
|
||||
final saved = await showDialog<bool>(
|
||||
Future<void> _openGestionnaireEditDialog(AppUser user) async {
|
||||
final changed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setStateDialog) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
'Rattacher ${user.fullName.isEmpty ? user.email : user.fullName}',
|
||||
),
|
||||
content: DropdownButtonFormField<String?>(
|
||||
value: selectedRelaisId,
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Relais principal',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem<String?>(
|
||||
value: null,
|
||||
child: Text('Aucun relais'),
|
||||
),
|
||||
..._relais.map(
|
||||
(relais) => DropdownMenuItem<String?>(
|
||||
value: relais.id,
|
||||
child: Text(relais.nom),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setStateDialog(() {
|
||||
selectedRelaisId = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Enregistrer'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) {
|
||||
return GestionnaireCreateDialog(initialUser: user);
|
||||
},
|
||||
);
|
||||
|
||||
if (saved != true) return;
|
||||
|
||||
try {
|
||||
await UserService.updateGestionnaireRelais(
|
||||
gestionnaireId: user.id,
|
||||
relaisId: selectedRelaisId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (changed == true) {
|
||||
await _loadGestionnaires();
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Rattachement relais mis a jour.')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
e.toString().replaceAll('Exception: ', ''),
|
||||
),
|
||||
backgroundColor: Colors.red.shade600,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,16 +93,11 @@ class _GestionnaireManagementWidgetState
|
||||
'Relais : ${user.relaisNom ?? 'Non rattaché'}',
|
||||
],
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.location_city_outlined),
|
||||
tooltip: 'Rattacher un relais',
|
||||
onPressed: () => _openRelaisAssignmentDialog(user),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
tooltip: 'Modifier',
|
||||
onPressed: () {
|
||||
// TODO: Modifier gestionnaire.
|
||||
_openGestionnaireEditDialog(user);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user