feat(#95): implémenter la gestion Relais admin et le rattachement gestionnaire
Ajoute la section Paramètres territoriaux avec CRUD Relais, modale de saisie structurée, états visuels harmonisés, et rattachement d'un relais principal aux gestionnaires via l'API. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
135c7c2255
commit
fbafef8f2c
33
frontend/lib/models/relais_model.dart
Normal file
33
frontend/lib/models/relais_model.dart
Normal file
@ -0,0 +1,33 @@
|
||||
class RelaisModel {
|
||||
final String id;
|
||||
final String nom;
|
||||
final String adresse;
|
||||
final Map<String, dynamic>? horairesOuverture;
|
||||
final String? ligneFixe;
|
||||
final bool actif;
|
||||
final String? notes;
|
||||
|
||||
const RelaisModel({
|
||||
required this.id,
|
||||
required this.nom,
|
||||
required this.adresse,
|
||||
this.horairesOuverture,
|
||||
this.ligneFixe,
|
||||
required this.actif,
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory RelaisModel.fromJson(Map<String, dynamic> json) {
|
||||
return RelaisModel(
|
||||
id: (json['id'] ?? '').toString(),
|
||||
nom: (json['nom'] ?? '').toString(),
|
||||
adresse: (json['adresse'] ?? '').toString(),
|
||||
horairesOuverture: json['horaires_ouverture'] is Map<String, dynamic>
|
||||
? json['horaires_ouverture'] as Map<String, dynamic>
|
||||
: null,
|
||||
ligneFixe: json['ligne_fixe'] as String?,
|
||||
actif: json['actif'] as bool? ?? true,
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,8 @@ class AppUser {
|
||||
final String? adresse;
|
||||
final String? ville;
|
||||
final String? codePostal;
|
||||
final String? relaisId;
|
||||
final String? relaisNom;
|
||||
|
||||
AppUser({
|
||||
required this.id,
|
||||
@ -29,9 +31,15 @@ class AppUser {
|
||||
this.adresse,
|
||||
this.ville,
|
||||
this.codePostal,
|
||||
this.relaisId,
|
||||
this.relaisNom,
|
||||
});
|
||||
|
||||
factory AppUser.fromJson(Map<String, dynamic> json) {
|
||||
final relaisJson = json['relais'];
|
||||
final relaisMap =
|
||||
relaisJson is Map<String, dynamic> ? relaisJson : <String, dynamic>{};
|
||||
|
||||
return AppUser(
|
||||
id: json['id'] as String,
|
||||
email: json['email'] as String,
|
||||
@ -56,6 +64,9 @@ class AppUser {
|
||||
adresse: json['adresse'] as String?,
|
||||
ville: json['ville'] as String?,
|
||||
codePostal: json['code_postal'] as String?,
|
||||
relaisId: (json['relaisId'] ?? json['relais_id'] ?? relaisMap['id'])
|
||||
?.toString(),
|
||||
relaisNom: relaisMap['nom']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -75,6 +86,8 @@ class AppUser {
|
||||
'adresse': adresse,
|
||||
'ville': ville,
|
||||
'code_postal': codePostal,
|
||||
'relais_id': relaisId,
|
||||
'relais_nom': relaisNom,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
bool? _setupCompleted;
|
||||
int mainTabIndex = 0;
|
||||
int subIndex = 0;
|
||||
int settingsSubIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -35,10 +36,12 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
if (!completed) mainTabIndex = 1;
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted) setState(() {
|
||||
_setupCompleted = false;
|
||||
mainTabIndex = 1;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_setupCompleted = false;
|
||||
mainTabIndex = 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +57,12 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
void onSettingsSubTabChange(int index) {
|
||||
setState(() {
|
||||
settingsSubIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_setupCompleted == null) {
|
||||
@ -83,6 +92,11 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
DashboardUserManagementSubBar(
|
||||
selectedSubIndex: subIndex,
|
||||
onSubTabChange: onSubTabChange,
|
||||
)
|
||||
else
|
||||
DashboardSettingsSubBar(
|
||||
selectedSubIndex: settingsSubIndex,
|
||||
onSubTabChange: onSettingsSubTabChange,
|
||||
),
|
||||
Expanded(
|
||||
child: _getBody(),
|
||||
@ -95,7 +109,10 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
|
||||
Widget _getBody() {
|
||||
if (mainTabIndex == 1) {
|
||||
return ParametresPanel(redirectToLoginAfterSave: !_setupCompleted!);
|
||||
return ParametresPanel(
|
||||
redirectToLoginAfterSave: !_setupCompleted!,
|
||||
selectedSettingsTabIndex: settingsSubIndex,
|
||||
);
|
||||
}
|
||||
switch (subIndex) {
|
||||
case 0:
|
||||
|
||||
@ -18,11 +18,13 @@ class ApiConfig {
|
||||
static const String gestionnaires = '/gestionnaires';
|
||||
static const String parents = '/parents';
|
||||
static const String assistantesMaternelles = '/assistantes-maternelles';
|
||||
static const String relais = '/relais';
|
||||
|
||||
// Configuration (admin)
|
||||
static const String configuration = '/configuration';
|
||||
static const String configurationSetupStatus = '/configuration/setup/status';
|
||||
static const String configurationSetupComplete = '/configuration/setup/complete';
|
||||
static const String configurationSetupComplete =
|
||||
'/configuration/setup/complete';
|
||||
static const String configurationTestSmtp = '/configuration/test-smtp';
|
||||
static const String configurationBulk = '/configuration/bulk';
|
||||
|
||||
@ -33,14 +35,14 @@ class ApiConfig {
|
||||
static const String conversations = '/conversations';
|
||||
static const String notifications = '/notifications';
|
||||
|
||||
// Headers
|
||||
// Headers
|
||||
static Map<String, String> get headers => {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
};
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
};
|
||||
|
||||
static Map<String, String> authHeaders(String token) => {
|
||||
...headers,
|
||||
'Authorization': 'Bearer $token',
|
||||
};
|
||||
}
|
||||
...headers,
|
||||
'Authorization': 'Bearer $token',
|
||||
};
|
||||
}
|
||||
|
||||
97
frontend/lib/services/relais_service.dart
Normal file
97
frontend/lib/services/relais_service.dart
Normal file
@ -0,0 +1,97 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:p_tits_pas/models/relais_model.dart';
|
||||
import 'package:p_tits_pas/services/api/api_config.dart';
|
||||
import 'package:p_tits_pas/services/api/tokenService.dart';
|
||||
|
||||
class RelaisService {
|
||||
static Future<Map<String, String>> _headers() async {
|
||||
final token = await TokenService.getToken();
|
||||
return token != null
|
||||
? ApiConfig.authHeaders(token)
|
||||
: Map<String, String>.from(ApiConfig.headers);
|
||||
}
|
||||
|
||||
static String _extractError(String body, String fallback) {
|
||||
try {
|
||||
final decoded = jsonDecode(body);
|
||||
if (decoded is Map<String, dynamic>) {
|
||||
final message = decoded['message'];
|
||||
if (message is String && message.trim().isNotEmpty) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static Future<List<RelaisModel>> getRelais() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.relais}'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
_extractError(response.body, 'Erreur chargement relais'),
|
||||
);
|
||||
}
|
||||
|
||||
final List<dynamic> data = jsonDecode(response.body);
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(RelaisModel.fromJson)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static Future<RelaisModel> createRelais(Map<String, dynamic> payload) async {
|
||||
final response = await http.post(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.relais}'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(payload),
|
||||
);
|
||||
|
||||
if (response.statusCode != 201 && response.statusCode != 200) {
|
||||
throw Exception(
|
||||
_extractError(response.body, 'Erreur création relais'),
|
||||
);
|
||||
}
|
||||
|
||||
return RelaisModel.fromJson(
|
||||
jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<RelaisModel> updateRelais(
|
||||
String id,
|
||||
Map<String, dynamic> payload,
|
||||
) async {
|
||||
final response = await http.patch(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.relais}/$id'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(payload),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
_extractError(response.body, 'Erreur mise à jour relais'),
|
||||
);
|
||||
}
|
||||
|
||||
return RelaisModel.fromJson(
|
||||
jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<void> deleteRelais(String id) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.relais}/$id'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception(
|
||||
_extractError(response.body, 'Erreur suppression relais'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,8 @@ class UserService {
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
final err = jsonDecode(response.body) as Map<String, dynamic>?;
|
||||
throw Exception(_toStr(err?['message']) ?? 'Erreur chargement gestionnaires');
|
||||
throw Exception(
|
||||
_toStr(err?['message']) ?? 'Erreur chargement gestionnaires');
|
||||
}
|
||||
|
||||
final List<dynamic> data = jsonDecode(response.body);
|
||||
@ -53,7 +54,8 @@ class UserService {
|
||||
}
|
||||
|
||||
// Récupérer la liste des assistantes maternelles
|
||||
static Future<List<AssistanteMaternelleModel>> getAssistantesMaternelles() async {
|
||||
static Future<List<AssistanteMaternelleModel>>
|
||||
getAssistantesMaternelles() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.assistantesMaternelles}'),
|
||||
headers: await _headers(),
|
||||
@ -87,8 +89,27 @@ class UserService {
|
||||
.toList();
|
||||
}
|
||||
} catch (e) {
|
||||
print('Erreur chargement admins: $e');
|
||||
// On garde un fallback vide pour ne pas bloquer l'UI admin.
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
static Future<void> updateGestionnaireRelais({
|
||||
required String gestionnaireId,
|
||||
required String? relaisId,
|
||||
}) async {
|
||||
final response = await http.patch(
|
||||
Uri.parse(
|
||||
'${ApiConfig.baseUrl}${ApiConfig.gestionnaires}/$gestionnaireId'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(<String, dynamic>{'relaisId': relaisId}),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
final err = jsonDecode(response.body) as Map<String, dynamic>?;
|
||||
throw Exception(
|
||||
_toStr(err?['message']) ?? 'Erreur rattachement relais au gestionnaire',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:p_tits_pas/services/auth_service.dart';
|
||||
|
||||
/// Barre du dashboard admin : onglets Gestion des utilisateurs | Paramètres + déconnexion.
|
||||
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
||||
class DashboardAppBarAdmin extends StatelessWidget
|
||||
implements PreferredSizeWidget {
|
||||
final int selectedIndex;
|
||||
final ValueChanged<int> onTabChange;
|
||||
final bool setupCompleted;
|
||||
@ -36,7 +37,8 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildNavItem(context, 'Gestion des utilisateurs', 0, enabled: setupCompleted),
|
||||
_buildNavItem(context, 'Gestion des utilisateurs', 0,
|
||||
enabled: setupCompleted),
|
||||
const SizedBox(width: 24),
|
||||
_buildNavItem(context, 'Paramètres', 1, enabled: true),
|
||||
],
|
||||
@ -78,7 +80,8 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem(BuildContext context, String title, int index, {bool enabled = true}) {
|
||||
Widget _buildNavItem(BuildContext context, String title, int index,
|
||||
{bool enabled = true}) {
|
||||
final bool isActive = index == selectedIndex;
|
||||
return InkWell(
|
||||
onTap: enabled ? () => onTabChange(index) : null,
|
||||
@ -189,3 +192,60 @@ class DashboardUserManagementSubBar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sous-barre Paramètres : Paramètres généraux | Paramètres territoriaux.
|
||||
class DashboardSettingsSubBar extends StatelessWidget {
|
||||
final int selectedSubIndex;
|
||||
final ValueChanged<int> onSubTabChange;
|
||||
|
||||
const DashboardSettingsSubBar({
|
||||
Key? key,
|
||||
required this.selectedSubIndex,
|
||||
required this.onSubTabChange,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
border: Border(bottom: BorderSide(color: Colors.grey.shade300)),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 6),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildSubNavItem(context, 'Paramètres généraux', 0),
|
||||
const SizedBox(width: 16),
|
||||
_buildSubNavItem(context, 'Paramètres territoriaux', 1),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSubNavItem(BuildContext context, String title, int index) {
|
||||
final bool isActive = index == selectedSubIndex;
|
||||
return InkWell(
|
||||
onTap: () => onSubTabChange(index),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? const Color(0xFF9CC5C0) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: isActive ? null : Border.all(color: Colors.black26),
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: isActive ? Colors.white : Colors.black87,
|
||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
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/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/gestionnaire_card.dart';
|
||||
|
||||
class GestionnaireManagementWidget extends StatefulWidget {
|
||||
const GestionnaireManagementWidget({Key? key}) : super(key: key);
|
||||
@ -16,6 +17,7 @@ class _GestionnaireManagementWidgetState
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
List<AppUser> _gestionnaires = [];
|
||||
List<RelaisModel> _relais = [];
|
||||
List<AppUser> _filteredGestionnaires = [];
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
@ -38,11 +40,19 @@ class _GestionnaireManagementWidgetState
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final list = await UserService.getGestionnaires();
|
||||
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 = list;
|
||||
_filteredGestionnaires = list;
|
||||
_gestionnaires = gestionnaires;
|
||||
_relais = relais;
|
||||
_filteredGestionnaires = gestionnaires;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
@ -65,6 +75,84 @@ class _GestionnaireManagementWidgetState
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _openRelaisAssignmentDialog(AppUser user) async {
|
||||
String? selectedRelaisId = user.relaisId;
|
||||
final saved = 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'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (saved != true) return;
|
||||
|
||||
try {
|
||||
await UserService.updateGestionnaireRelais(
|
||||
gestionnaireId: user.id,
|
||||
relaisId: selectedRelaisId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
@ -72,14 +160,13 @@ class _GestionnaireManagementWidgetState
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// 🔹 Barre du haut avec bouton
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Rechercher un gestionnaire...",
|
||||
hintText: 'Rechercher un gestionnaire...',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
@ -88,35 +175,70 @@ class _GestionnaireManagementWidgetState
|
||||
const SizedBox(width: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
// TODO: Rediriger vers la page de création
|
||||
// TODO: Rediriger vers la page de creation.
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Créer un gestionnaire"),
|
||||
label: const Text('Creer un gestionnaire'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 🔹 Liste des gestionnaires
|
||||
if (_isLoading)
|
||||
const Center(child: CircularProgressIndicator())
|
||||
else if (_error != null)
|
||||
Center(child: Text('Erreur: $_error', style: const TextStyle(color: Colors.red)))
|
||||
Center(
|
||||
child: Text(
|
||||
'Erreur: $_error',
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
)
|
||||
else if (_filteredGestionnaires.isEmpty)
|
||||
const Center(child: Text("Aucun gestionnaire trouvé."))
|
||||
const Center(child: Text('Aucun gestionnaire trouve.'))
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _filteredGestionnaires.length,
|
||||
itemBuilder: (context, index) {
|
||||
final user = _filteredGestionnaires[index];
|
||||
return GestionnaireCard(
|
||||
name: user.fullName.isNotEmpty ? user.fullName : "Sans nom",
|
||||
email: user.email,
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
child: Text(
|
||||
(user.prenom?.isNotEmpty == true
|
||||
? user.prenom!.substring(0, 1)
|
||||
: user.email.substring(0, 1))
|
||||
.toUpperCase(),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
user.fullName.isNotEmpty ? user.fullName : 'Sans nom',
|
||||
),
|
||||
subtitle: Text(
|
||||
'${user.email} • Relais: ${user.relaisNom ?? 'Non rattache'}',
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
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.
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:p_tits_pas/services/configuration_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/relais_management_panel.dart';
|
||||
|
||||
/// Panneau Paramètres admin : Email (SMTP), Personnalisation, Avancé.
|
||||
class ParametresPanel extends StatefulWidget {
|
||||
/// Si true, après sauvegarde on redirige vers le login (première config). Sinon on reste sur la page.
|
||||
final bool redirectToLoginAfterSave;
|
||||
final int selectedSettingsTabIndex;
|
||||
|
||||
const ParametresPanel({super.key, this.redirectToLoginAfterSave = false});
|
||||
const ParametresPanel({
|
||||
super.key,
|
||||
this.redirectToLoginAfterSave = false,
|
||||
this.selectedSettingsTabIndex = 0,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ParametresPanel> createState() => _ParametresPanelState();
|
||||
@ -33,10 +39,18 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
|
||||
void _createControllers() {
|
||||
final keys = [
|
||||
'smtp_host', 'smtp_port', 'smtp_user', 'smtp_password',
|
||||
'email_from_name', 'email_from_address',
|
||||
'app_name', 'app_url', 'app_logo_url',
|
||||
'password_reset_token_expiry_days', 'jwt_expiry_hours', 'max_upload_size_mb',
|
||||
'smtp_host',
|
||||
'smtp_port',
|
||||
'smtp_user',
|
||||
'smtp_password',
|
||||
'email_from_name',
|
||||
'email_from_address',
|
||||
'app_name',
|
||||
'app_url',
|
||||
'app_logo_url',
|
||||
'password_reset_token_expiry_days',
|
||||
'jwt_expiry_hours',
|
||||
'max_upload_size_mb',
|
||||
];
|
||||
for (final k in keys) {
|
||||
_controllers[k] = TextEditingController();
|
||||
@ -93,18 +107,29 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
payload['smtp_auth_required'] = _smtpAuthRequired;
|
||||
payload['smtp_user'] = _controllers['smtp_user']!.text.trim();
|
||||
final pwd = _controllers['smtp_password']!.text.trim();
|
||||
if (pwd.isNotEmpty && pwd != '***********') payload['smtp_password'] = pwd;
|
||||
if (pwd.isNotEmpty && pwd != '***********') {
|
||||
payload['smtp_password'] = pwd;
|
||||
}
|
||||
payload['email_from_name'] = _controllers['email_from_name']!.text.trim();
|
||||
payload['email_from_address'] = _controllers['email_from_address']!.text.trim();
|
||||
payload['email_from_address'] =
|
||||
_controllers['email_from_address']!.text.trim();
|
||||
payload['app_name'] = _controllers['app_name']!.text.trim();
|
||||
payload['app_url'] = _controllers['app_url']!.text.trim();
|
||||
payload['app_logo_url'] = _controllers['app_logo_url']!.text.trim();
|
||||
final tokenDays = int.tryParse(_controllers['password_reset_token_expiry_days']!.text.trim());
|
||||
if (tokenDays != null) payload['password_reset_token_expiry_days'] = tokenDays;
|
||||
final jwtHours = int.tryParse(_controllers['jwt_expiry_hours']!.text.trim());
|
||||
if (jwtHours != null) payload['jwt_expiry_hours'] = jwtHours;
|
||||
final tokenDays = int.tryParse(
|
||||
_controllers['password_reset_token_expiry_days']!.text.trim());
|
||||
if (tokenDays != null) {
|
||||
payload['password_reset_token_expiry_days'] = tokenDays;
|
||||
}
|
||||
final jwtHours =
|
||||
int.tryParse(_controllers['jwt_expiry_hours']!.text.trim());
|
||||
if (jwtHours != null) {
|
||||
payload['jwt_expiry_hours'] = jwtHours;
|
||||
}
|
||||
final maxMb = int.tryParse(_controllers['max_upload_size_mb']!.text.trim());
|
||||
if (maxMb != null) payload['max_upload_size_mb'] = maxMb;
|
||||
if (maxMb != null) {
|
||||
payload['max_upload_size_mb'] = maxMb;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
@ -191,6 +216,10 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.selectedSettingsTabIndex == 1) {
|
||||
return const RelaisManagementPanel();
|
||||
}
|
||||
|
||||
if (_isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
@ -214,7 +243,8 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
}
|
||||
|
||||
final isSuccess = _message != null &&
|
||||
(_message!.startsWith('Configuration') || _message!.startsWith('Connexion'));
|
||||
(_message!.startsWith('Configuration') ||
|
||||
_message!.startsWith('Connexion'));
|
||||
|
||||
return Form(
|
||||
key: _formKey,
|
||||
@ -234,12 +264,21 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
context,
|
||||
icon: Icons.email_outlined,
|
||||
title: 'Configuration Email (SMTP)',
|
||||
child: Column(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildField('smtp_host', 'Serveur SMTP', hint: 'mail.example.com'),
|
||||
_buildField(
|
||||
'smtp_host',
|
||||
'Serveur SMTP',
|
||||
hint: 'mail.example.com',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('smtp_port', 'Port SMTP', keyboard: TextInputType.number, hint: '25, 465, 587'),
|
||||
_buildField(
|
||||
'smtp_port',
|
||||
'Port SMTP',
|
||||
keyboard: TextInputType.number,
|
||||
hint: '25, 465, 587',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 14),
|
||||
@ -247,14 +286,17 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _smtpSecure,
|
||||
onChanged: (v) => setState(() => _smtpSecure = v ?? false),
|
||||
onChanged: (v) =>
|
||||
setState(() => _smtpSecure = v ?? false),
|
||||
activeColor: const Color(0xFF9CC5C0),
|
||||
),
|
||||
const Text('SSL/TLS (secure)'),
|
||||
const SizedBox(width: 24),
|
||||
Checkbox(
|
||||
value: _smtpAuthRequired,
|
||||
onChanged: (v) => setState(() => _smtpAuthRequired = v ?? false),
|
||||
onChanged: (v) => setState(
|
||||
() => _smtpAuthRequired = v ?? false,
|
||||
),
|
||||
activeColor: const Color(0xFF9CC5C0),
|
||||
),
|
||||
const Text('Authentification requise'),
|
||||
@ -263,11 +305,19 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
),
|
||||
_buildField('smtp_user', 'Utilisateur SMTP'),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('smtp_password', 'Mot de passe SMTP', obscure: true),
|
||||
_buildField(
|
||||
'smtp_password',
|
||||
'Mot de passe SMTP',
|
||||
obscure: true,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('email_from_name', 'Nom expéditeur'),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('email_from_address', 'Email expéditeur', hint: 'no-reply@example.com'),
|
||||
_buildField(
|
||||
'email_from_address',
|
||||
'Email expéditeur',
|
||||
hint: 'no-reply@example.com',
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
@ -277,8 +327,13 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
label: const Text('Tester la connexion SMTP'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF2D6A4F),
|
||||
side: const BorderSide(color: Color(0xFF9CC5C0)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
side: const BorderSide(
|
||||
color: Color(0xFF9CC5C0),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -290,14 +345,22 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
context,
|
||||
icon: Icons.palette_outlined,
|
||||
title: 'Personnalisation',
|
||||
child: Column(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildField('app_name', 'Nom de l\'application'),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('app_url', 'URL de l\'application', hint: 'https://app.example.com'),
|
||||
_buildField(
|
||||
'app_url',
|
||||
'URL de l\'application',
|
||||
hint: 'https://app.example.com',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('app_logo_url', 'URL du logo', hint: '/assets/logo.png'),
|
||||
_buildField(
|
||||
'app_logo_url',
|
||||
'URL du logo',
|
||||
hint: '/assets/logo.png',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -309,11 +372,23 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildField('password_reset_token_expiry_days', 'Validité token MDP (jours)', keyboard: TextInputType.number),
|
||||
_buildField(
|
||||
'password_reset_token_expiry_days',
|
||||
'Validité token MDP (jours)',
|
||||
keyboard: TextInputType.number,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('jwt_expiry_hours', 'Validité session JWT (heures)', keyboard: TextInputType.number),
|
||||
_buildField(
|
||||
'jwt_expiry_hours',
|
||||
'Validité session JWT (heures)',
|
||||
keyboard: TextInputType.number,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField('max_upload_size_mb', 'Taille max upload (MB)', keyboard: TextInputType.number),
|
||||
_buildField(
|
||||
'max_upload_size_mb',
|
||||
'Taille max upload (MB)',
|
||||
keyboard: TextInputType.number,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -327,7 +402,14 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: _isSaving
|
||||
? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
? const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('Sauvegarder la configuration'),
|
||||
),
|
||||
),
|
||||
@ -339,7 +421,8 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionCard(BuildContext context, {required IconData icon, required String title, required Widget child}) {
|
||||
Widget _buildSectionCard(BuildContext context,
|
||||
{required IconData icon, required String title, required Widget child}) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
@ -369,7 +452,8 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildField(String key, String label, {bool obscure = false, TextInputType? keyboard, String? hint}) {
|
||||
Widget _buildField(String key, String label,
|
||||
{bool obscure = false, TextInputType? keyboard, String? hint}) {
|
||||
final c = _controllers[key];
|
||||
if (c == null) return const SizedBox.shrink();
|
||||
return TextFormField(
|
||||
@ -381,7 +465,8 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
1134
frontend/lib/widgets/admin/relais_management_panel.dart
Normal file
1134
frontend/lib/widgets/admin/relais_management_panel.dart
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user