feat(#140): dashboard admin ch.6 — fiche parent, enfants, affiliation
Back: PATCH /parents/:id/fiche, attach/detach enfant, GET /enfants enrichi. Front: modale parent éditable, onglet Enfants, fiche enfant, UserService. Couvre doc 28 §6.1–6.2 ; tickets liés #115 #116 #130 #131 #137 #138. Hors scope: fiche AM (#131), création admin (#129). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import 'package:p_tits_pas/models/user.dart';
|
||||
|
||||
/// Enfant tel que renvoyé par `GET /enfants` (dashboard admin).
|
||||
class EnfantAdminModel {
|
||||
final String id;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String? gender;
|
||||
final String? birthDate;
|
||||
final String? dueDate;
|
||||
final String status;
|
||||
final String? photoUrl;
|
||||
final bool consentPhoto;
|
||||
final bool isMultiple;
|
||||
final List<EnfantParentLink> parentLinks;
|
||||
|
||||
EnfantAdminModel({
|
||||
required this.id,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
this.gender,
|
||||
this.birthDate,
|
||||
this.dueDate,
|
||||
required this.status,
|
||||
this.photoUrl,
|
||||
this.consentPhoto = false,
|
||||
this.isMultiple = false,
|
||||
this.parentLinks = const [],
|
||||
});
|
||||
|
||||
String get fullName {
|
||||
final fn = (firstName ?? '').trim();
|
||||
final ln = (lastName ?? '').trim();
|
||||
if (fn.isEmpty && ln.isEmpty) return 'Enfant';
|
||||
if (ln.isEmpty) return fn;
|
||||
return '$fn $ln';
|
||||
}
|
||||
|
||||
factory EnfantAdminModel.fromJson(Map<String, dynamic> json) {
|
||||
final linksRaw = json['parentLinks'] as List?;
|
||||
final links = <EnfantParentLink>[];
|
||||
if (linksRaw != null) {
|
||||
for (final item in linksRaw) {
|
||||
if (item is Map<String, dynamic>) {
|
||||
links.add(EnfantParentLink.fromJson(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EnfantAdminModel(
|
||||
id: (json['id'] ?? '').toString(),
|
||||
firstName: json['first_name'] as String?,
|
||||
lastName: json['last_name'] as String?,
|
||||
gender: json['gender'] as String?,
|
||||
birthDate: _dateString(json['birth_date']),
|
||||
dueDate: _dateString(json['due_date']),
|
||||
status: (json['status'] ?? '').toString(),
|
||||
photoUrl: json['photo_url'] as String?,
|
||||
consentPhoto: json['consent_photo'] == true,
|
||||
isMultiple: json['is_multiple'] == true,
|
||||
parentLinks: links,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toUpdateJson() {
|
||||
return {
|
||||
if (firstName != null) 'first_name': firstName,
|
||||
if (lastName != null) 'last_name': lastName,
|
||||
if (gender != null && gender!.isNotEmpty) 'gender': gender,
|
||||
'status': status,
|
||||
if (birthDate != null && birthDate!.isNotEmpty) 'birth_date': birthDate,
|
||||
if (dueDate != null && dueDate!.isNotEmpty) 'due_date': dueDate,
|
||||
'consent_photo': consentPhoto,
|
||||
'is_multiple': isMultiple,
|
||||
};
|
||||
}
|
||||
|
||||
static String? _dateString(dynamic v) {
|
||||
if (v == null) return null;
|
||||
if (v is String) return v.split('T').first;
|
||||
return v.toString().split('T').first;
|
||||
}
|
||||
}
|
||||
|
||||
class EnfantParentLink {
|
||||
final String parentId;
|
||||
final String? parentName;
|
||||
|
||||
EnfantParentLink({required this.parentId, this.parentName});
|
||||
|
||||
factory EnfantParentLink.fromJson(Map<String, dynamic> json) {
|
||||
final parent = json['parent'];
|
||||
String? name;
|
||||
if (parent is Map<String, dynamic>) {
|
||||
final user = parent['user'];
|
||||
if (user is Map<String, dynamic>) {
|
||||
final u = AppUser.fromJson(user);
|
||||
name = u.fullName.isNotEmpty ? u.fullName : u.email;
|
||||
}
|
||||
}
|
||||
return EnfantParentLink(
|
||||
parentId: (json['parentId'] ?? json['id_parent'] ?? '').toString(),
|
||||
parentName: name,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/// Résumé enfant affiché dans la fiche parent (dashboard admin).
|
||||
class ParentChildSummary {
|
||||
final String id;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String status;
|
||||
|
||||
ParentChildSummary({
|
||||
required this.id,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
required this.status,
|
||||
});
|
||||
|
||||
String get fullName {
|
||||
final fn = (firstName ?? '').trim();
|
||||
final ln = (lastName ?? '').trim();
|
||||
if (fn.isEmpty && ln.isEmpty) return 'Enfant';
|
||||
if (ln.isEmpty) return fn;
|
||||
return '$fn $ln';
|
||||
}
|
||||
|
||||
factory ParentChildSummary.fromJson(Map<String, dynamic> json) {
|
||||
return ParentChildSummary(
|
||||
id: (json['id'] ?? '').toString(),
|
||||
firstName: json['first_name'] as String?,
|
||||
lastName: json['last_name'] as String?,
|
||||
status: (json['status'] ?? '').toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,40 @@
|
||||
import 'package:p_tits_pas/models/parent_child_summary.dart';
|
||||
import 'package:p_tits_pas/models/user.dart';
|
||||
|
||||
class ParentModel {
|
||||
final AppUser user;
|
||||
final int childrenCount;
|
||||
final List<ParentChildSummary> children;
|
||||
|
||||
ParentModel({required this.user, this.childrenCount = 0});
|
||||
ParentModel({
|
||||
required this.user,
|
||||
this.childrenCount = 0,
|
||||
this.children = const [],
|
||||
});
|
||||
|
||||
factory ParentModel.fromJson(Map<String, dynamic> json) {
|
||||
final userJson = json['user'] ?? json;
|
||||
final userJson = Map<String, dynamic>.from(json['user'] ?? json);
|
||||
if (json['numero_dossier'] != null && userJson['numero_dossier'] == null) {
|
||||
userJson['numero_dossier'] = json['numero_dossier'];
|
||||
}
|
||||
final user = AppUser.fromJson(userJson);
|
||||
final children = json['parentChildren'] as List?;
|
||||
|
||||
final children = <ParentChildSummary>[];
|
||||
final links = json['parentChildren'] as List?;
|
||||
if (links != null) {
|
||||
for (final link in links) {
|
||||
if (link is Map<String, dynamic> && link['child'] is Map<String, dynamic>) {
|
||||
children.add(
|
||||
ParentChildSummary.fromJson(link['child'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ParentModel(
|
||||
user: user,
|
||||
childrenCount: children?.length ?? 0,
|
||||
childrenCount: children.isNotEmpty ? children.length : (links?.length ?? 0),
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ class ApiConfig {
|
||||
static const String gestionnaires = '/gestionnaires';
|
||||
static const String parents = '/parents';
|
||||
static const String assistantesMaternelles = '/assistantes-maternelles';
|
||||
static const String enfants = '/enfants';
|
||||
static const String relais = '/relais';
|
||||
static const String dossiers = '/dossiers';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:p_tits_pas/models/user.dart';
|
||||
import 'package:p_tits_pas/models/enfant_admin_model.dart';
|
||||
import 'package:p_tits_pas/models/parent_model.dart';
|
||||
import 'package:p_tits_pas/models/assistante_maternelle_model.dart';
|
||||
import 'package:p_tits_pas/models/pending_family.dart';
|
||||
@@ -369,6 +370,123 @@ class UserService {
|
||||
return data.map((e) => ParentModel.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
static Future<ParentModel> getParent(String userId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.parents}/$userId'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
final err = jsonDecode(response.body) as Map<String, dynamic>?;
|
||||
throw Exception(_toStr(err?['message']) ?? 'Erreur chargement parent');
|
||||
}
|
||||
return ParentModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<ParentModel> updateParentFiche({
|
||||
required String parentUserId,
|
||||
required Map<String, dynamic> body,
|
||||
}) async {
|
||||
final response = await http.patch(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.parents}/$parentUserId/fiche'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur mise à jour parent'));
|
||||
}
|
||||
return ParentModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<ParentModel> attachEnfantToParent({
|
||||
required String parentUserId,
|
||||
required String enfantId,
|
||||
}) async {
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
'${ApiConfig.baseUrl}${ApiConfig.parents}/$parentUserId/enfants/$enfantId',
|
||||
),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 201) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur rattachement enfant'));
|
||||
}
|
||||
return ParentModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<ParentModel> detachEnfantFromParent({
|
||||
required String parentUserId,
|
||||
required String enfantId,
|
||||
}) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse(
|
||||
'${ApiConfig.baseUrl}${ApiConfig.parents}/$parentUserId/enfants/$enfantId',
|
||||
),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur détachement enfant'));
|
||||
}
|
||||
if (response.body.isEmpty) {
|
||||
return getParent(parentUserId);
|
||||
}
|
||||
return ParentModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<List<EnfantAdminModel>> getEnfants() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.enfants}'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur chargement enfants'));
|
||||
}
|
||||
final List<dynamic> data = jsonDecode(response.body);
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(EnfantAdminModel.fromJson)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static Future<EnfantAdminModel> getEnfant(String enfantId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.enfants}/$enfantId'),
|
||||
headers: await _headers(),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur chargement enfant'));
|
||||
}
|
||||
return EnfantAdminModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static Future<EnfantAdminModel> updateEnfant({
|
||||
required String enfantId,
|
||||
required Map<String, dynamic> body,
|
||||
}) async {
|
||||
final response = await http.patch(
|
||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.enfants}/$enfantId'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(_extractErrorMessage(response.body, 'Erreur mise à jour enfant'));
|
||||
}
|
||||
return EnfantAdminModel.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
static String _extractErrorMessage(String body, String fallback) {
|
||||
try {
|
||||
final decoded = jsonDecode(body);
|
||||
if (decoded is Map<String, dynamic>) {
|
||||
final message = decoded['message'];
|
||||
if (message is List && message.isNotEmpty) {
|
||||
return message.join(' - ');
|
||||
}
|
||||
return _toStr(message) ?? fallback;
|
||||
}
|
||||
} catch (_) {}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
// Récupérer la liste des assistantes maternelles
|
||||
static Future<List<AssistanteMaternelleModel>>
|
||||
getAssistantesMaternelles() async {
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/enfant_admin_model.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
|
||||
/// Fiche enfant consultation / édition (ticket #138).
|
||||
class AdminChildDetailModal extends StatefulWidget {
|
||||
final EnfantAdminModel enfant;
|
||||
final VoidCallback? onSaved;
|
||||
|
||||
const AdminChildDetailModal({
|
||||
super.key,
|
||||
required this.enfant,
|
||||
this.onSaved,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AdminChildDetailModal> createState() => _AdminChildDetailModalState();
|
||||
}
|
||||
|
||||
class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
|
||||
late final TextEditingController _prenomCtrl;
|
||||
late final TextEditingController _nomCtrl;
|
||||
late final TextEditingController _birthCtrl;
|
||||
late final TextEditingController _dueCtrl;
|
||||
late String _status;
|
||||
late String _gender;
|
||||
late bool _consentPhoto;
|
||||
late bool _isMultiple;
|
||||
bool _dirty = false;
|
||||
bool _saving = false;
|
||||
|
||||
static const _statuses = ['a_naitre', 'actif', 'scolarise'];
|
||||
static const _genders = ['H', 'F', 'Autre'];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final e = widget.enfant;
|
||||
_prenomCtrl = TextEditingController(text: e.firstName ?? '');
|
||||
_nomCtrl = TextEditingController(text: e.lastName ?? '');
|
||||
_birthCtrl = TextEditingController(text: e.birthDate ?? '');
|
||||
_dueCtrl = TextEditingController(text: e.dueDate ?? '');
|
||||
_status = _statuses.contains(e.status) ? e.status : 'actif';
|
||||
_gender = _genders.contains(e.gender) ? e.gender! : 'H';
|
||||
_consentPhoto = e.consentPhoto;
|
||||
_isMultiple = e.isMultiple;
|
||||
for (final c in [_prenomCtrl, _nomCtrl, _birthCtrl, _dueCtrl]) {
|
||||
c.addListener(_markDirty);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final c in [_prenomCtrl, _nomCtrl, _birthCtrl, _dueCtrl]) {
|
||||
c.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _markDirty() {
|
||||
if (!_dirty) setState(() => _dirty = true);
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
if (!_dirty) return;
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
await UserService.updateEnfant(
|
||||
enfantId: widget.enfant.id,
|
||||
body: {
|
||||
'first_name': _prenomCtrl.text.trim(),
|
||||
'last_name': _nomCtrl.text.trim(),
|
||||
'status': _status,
|
||||
'gender': _gender,
|
||||
if (_birthCtrl.text.trim().isNotEmpty) 'birth_date': _birthCtrl.text.trim(),
|
||||
if (_dueCtrl.text.trim().isNotEmpty) 'due_date': _dueCtrl.text.trim(),
|
||||
'consent_photo': _consentPhoto,
|
||||
'is_multiple': _isMultiple,
|
||||
},
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_dirty = false;
|
||||
_saving = false;
|
||||
});
|
||||
widget.onSaved?.call();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Fiche enfant enregistrée')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _saving = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parents = widget.enfant.parentLinks
|
||||
.map((l) => l.parentName ?? l.parentId)
|
||||
.where((s) => s.isNotEmpty)
|
||||
.join(', ');
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 560, maxHeight: 640),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.enfant.fullName,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (parents.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text('Responsables : $parents', style: const TextStyle(color: Colors.black54)),
|
||||
),
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
_rowField('Prénom', TextField(controller: _prenomCtrl, decoration: _decoration())),
|
||||
_rowField('Nom', TextField(controller: _nomCtrl, decoration: _decoration())),
|
||||
_rowDropdown(
|
||||
'Statut',
|
||||
_status,
|
||||
_statuses.map((s) => MapEntry(s, _statusLabel(s))).toList(),
|
||||
(v) => setState(() {
|
||||
_status = v;
|
||||
_dirty = true;
|
||||
}),
|
||||
),
|
||||
_rowDropdown(
|
||||
'Genre',
|
||||
_gender,
|
||||
_genders.map((g) => MapEntry(g, g)).toList(),
|
||||
(v) => setState(() {
|
||||
_gender = v;
|
||||
_dirty = true;
|
||||
}),
|
||||
),
|
||||
_rowField(
|
||||
'Date naissance',
|
||||
TextField(
|
||||
controller: _birthCtrl,
|
||||
decoration: _decoration(hint: 'AAAA-MM-JJ'),
|
||||
),
|
||||
),
|
||||
_rowField(
|
||||
'Date prévue',
|
||||
TextField(
|
||||
controller: _dueCtrl,
|
||||
decoration: _decoration(hint: 'AAAA-MM-JJ'),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('Consentement photo'),
|
||||
value: _consentPhoto,
|
||||
onChanged: (v) => setState(() {
|
||||
_consentPhoto = v;
|
||||
_dirty = true;
|
||||
}),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('Naissance multiple'),
|
||||
value: _isMultiple,
|
||||
onChanged: (v) => setState(() {
|
||||
_isMultiple = v;
|
||||
_dirty = true;
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Fermer'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: !_dirty || _saving ? null : _save,
|
||||
icon: _saving
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.save),
|
||||
label: const Text('Sauvegarder'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _decoration({String? hint}) {
|
||||
return InputDecoration(isDense: true, border: const OutlineInputBorder(), hintText: hint);
|
||||
}
|
||||
|
||||
Widget _rowField(String label, Widget field) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Text(label, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
Expanded(child: field),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _rowDropdown(
|
||||
String label,
|
||||
String value,
|
||||
List<MapEntry<String, String>> items,
|
||||
ValueChanged<String> onChanged,
|
||||
) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: Text(label, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: items.any((e) => e.key == value) ? value : items.first.key,
|
||||
decoration: _decoration(),
|
||||
items: items
|
||||
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v != null) onChanged(v);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _statusLabel(String status) {
|
||||
switch (status) {
|
||||
case 'a_naitre':
|
||||
return 'À naître';
|
||||
case 'actif':
|
||||
return 'Actif';
|
||||
case 'scolarise':
|
||||
return 'Scolarisé';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/enfant_admin_model.dart';
|
||||
import 'package:p_tits_pas/models/parent_child_summary.dart';
|
||||
import 'package:p_tits_pas/models/parent_model.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/utils/phone_utils.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_child_detail_modal.dart';
|
||||
|
||||
/// Fiche parent éditable (doc 28 §6.1, tickets #131 / #138).
|
||||
class AdminParentEditModal extends StatefulWidget {
|
||||
final ParentModel parent;
|
||||
final VoidCallback? onSaved;
|
||||
|
||||
const AdminParentEditModal({
|
||||
super.key,
|
||||
required this.parent,
|
||||
this.onSaved,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AdminParentEditModal> createState() => _AdminParentEditModalState();
|
||||
}
|
||||
|
||||
class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
late final TextEditingController _nomCtrl;
|
||||
late final TextEditingController _prenomCtrl;
|
||||
late final TextEditingController _emailCtrl;
|
||||
late final TextEditingController _telCtrl;
|
||||
late final TextEditingController _adresseCtrl;
|
||||
late final TextEditingController _villeCtrl;
|
||||
late final TextEditingController _cpCtrl;
|
||||
|
||||
late String _statut;
|
||||
late List<ParentChildSummary> _children;
|
||||
bool _saving = false;
|
||||
bool _dirty = false;
|
||||
|
||||
static const _statuts = ['actif', 'en_attente', 'suspendu', 'refuse'];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final u = widget.parent.user;
|
||||
_nomCtrl = TextEditingController(text: u.nom ?? '');
|
||||
_prenomCtrl = TextEditingController(text: u.prenom ?? '');
|
||||
_emailCtrl = TextEditingController(text: u.email);
|
||||
_telCtrl = TextEditingController(text: u.telephone ?? '');
|
||||
_adresseCtrl = TextEditingController(text: u.adresse ?? '');
|
||||
_villeCtrl = TextEditingController(text: u.ville ?? '');
|
||||
_cpCtrl = TextEditingController(text: u.codePostal ?? '');
|
||||
_statut = u.statut ?? 'en_attente';
|
||||
_children = List.of(widget.parent.children);
|
||||
for (final c in [_nomCtrl, _prenomCtrl, _emailCtrl, _telCtrl, _adresseCtrl, _villeCtrl, _cpCtrl]) {
|
||||
c.addListener(_markDirty);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final c in [_nomCtrl, _prenomCtrl, _emailCtrl, _telCtrl, _adresseCtrl, _villeCtrl, _cpCtrl]) {
|
||||
c.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _markDirty() {
|
||||
if (!_dirty) setState(() => _dirty = true);
|
||||
}
|
||||
|
||||
String _displayStatus(String status) {
|
||||
switch (status) {
|
||||
case 'actif':
|
||||
return 'Actif';
|
||||
case 'en_attente':
|
||||
return 'En attente';
|
||||
case 'suspendu':
|
||||
return 'Suspendu';
|
||||
case 'refuse':
|
||||
return 'Refusé';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
if (!_dirty) return;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Confirmer'),
|
||||
content: const Text('Enregistrer les modifications de la fiche parent ?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Annuler')),
|
||||
ElevatedButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('Sauvegarder')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
await UserService.updateParentFiche(
|
||||
parentUserId: widget.parent.user.id,
|
||||
body: {
|
||||
'nom': _nomCtrl.text.trim(),
|
||||
'prenom': _prenomCtrl.text.trim(),
|
||||
'email': _emailCtrl.text.trim(),
|
||||
'telephone': _telCtrl.text.trim(),
|
||||
'adresse': _adresseCtrl.text.trim(),
|
||||
'ville': _villeCtrl.text.trim(),
|
||||
'code_postal': _cpCtrl.text.trim(),
|
||||
'statut': _statut,
|
||||
},
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_dirty = false;
|
||||
_saving = false;
|
||||
});
|
||||
widget.onSaved?.call();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Fiche parent enregistrée')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _saving = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openChild(ParentChildSummary child) async {
|
||||
try {
|
||||
final enfant = await UserService.getEnfant(child.id);
|
||||
if (!mounted) return;
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => AdminChildDetailModal(
|
||||
enfant: enfant,
|
||||
onSaved: () async {
|
||||
await _reloadChildren();
|
||||
},
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _reloadChildren() async {
|
||||
try {
|
||||
final refreshed = await UserService.getParent(widget.parent.user.id);
|
||||
if (!mounted) return;
|
||||
setState(() => _children = List.of(refreshed.children));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> _detachChild(ParentChildSummary child) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Détacher l\'enfant'),
|
||||
content: Text(
|
||||
'Retirer ${child.fullName} de la fiche de ce parent ?\n(L\'enfant ne sera pas supprimé.)',
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Annuler')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.red.shade700),
|
||||
child: const Text('Détacher'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
|
||||
try {
|
||||
final updated = await UserService.detachEnfantFromParent(
|
||||
parentUserId: widget.parent.user.id,
|
||||
enfantId: child.id,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _children = List.of(updated.children));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Enfant détaché')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _attachChild() async {
|
||||
List<EnfantAdminModel> all;
|
||||
try {
|
||||
all = await UserService.getEnfants();
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final linkedIds = _children.map((c) => c.id).toSet();
|
||||
final candidates = all.where((e) => !linkedIds.contains(e.id)).toList();
|
||||
if (candidates.isEmpty) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Aucun enfant disponible à rattacher')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
final selected = await showDialog<EnfantAdminModel>(
|
||||
context: context,
|
||||
builder: (ctx) => SimpleDialog(
|
||||
title: const Text('Rattacher un enfant'),
|
||||
children: candidates
|
||||
.map(
|
||||
(e) => SimpleDialogOption(
|
||||
onPressed: () => Navigator.pop(ctx, e),
|
||||
child: Text(e.fullName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
if (selected == null || !mounted) return;
|
||||
|
||||
try {
|
||||
final updated = await UserService.attachEnfantToParent(
|
||||
parentUserId: widget.parent.user.id,
|
||||
enfantId: selected.id,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _children = List.of(updated.children));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Enfant rattaché')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _field(String label, TextEditingController ctrl, {TextInputType? keyboard}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 130,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Text(label, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: ctrl,
|
||||
keyboardType: keyboard,
|
||||
decoration: const InputDecoration(isDense: true, border: OutlineInputBorder()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final numero = widget.parent.user.numeroDossier;
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 680, maxHeight: 720),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.parent.user.fullName.isEmpty
|
||||
? 'Parent'
|
||||
: widget.parent.user.fullName,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
|
||||
),
|
||||
Text(widget.parent.user.email, style: const TextStyle(color: Colors.black54)),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (numero != null && numero.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 130,
|
||||
child: Text('N° dossier', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
Expanded(child: Text(numero)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 130,
|
||||
child: Text('Statut', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: _statuts.contains(_statut) ? _statut : _statuts.first,
|
||||
decoration: const InputDecoration(isDense: true, border: OutlineInputBorder()),
|
||||
items: _statuts
|
||||
.map(
|
||||
(s) => DropdownMenuItem(
|
||||
value: s,
|
||||
child: Text(_displayStatus(s)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
setState(() {
|
||||
_statut = v;
|
||||
_dirty = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_field('Nom', _nomCtrl),
|
||||
_field('Prénom', _prenomCtrl),
|
||||
_field('Email', _emailCtrl, keyboard: TextInputType.emailAddress),
|
||||
_field('Téléphone', _telCtrl, keyboard: TextInputType.phone),
|
||||
if (_telCtrl.text.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 130, bottom: 4),
|
||||
child: Text(
|
||||
formatPhoneForDisplay(_telCtrl.text),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.black54),
|
||||
),
|
||||
),
|
||||
_field('Adresse', _adresseCtrl),
|
||||
_field('Ville', _villeCtrl),
|
||||
_field('Code postal', _cpCtrl),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Nombre d\'enfants : ${_children.length}',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: _children.isEmpty
|
||||
? const Text('Aucun enfant rattaché', style: TextStyle(color: Colors.black54))
|
||||
: Column(
|
||||
children: _children
|
||||
.map(
|
||||
(c) => ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: InkWell(
|
||||
onTap: () => _openChild(c),
|
||||
child: Text(
|
||||
c.fullName,
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
subtitle: Text(_childStatusLabel(c.status)),
|
||||
trailing: IconButton(
|
||||
tooltip: 'Détacher',
|
||||
icon: Icon(Icons.link_off, color: Colors.orange.shade800),
|
||||
onPressed: () => _detachChild(c),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: _attachChild,
|
||||
icon: const Icon(Icons.link),
|
||||
label: const Text('Rattacher un enfant'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: _saving ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Fermer'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: !_dirty || _saving ? null : _save,
|
||||
icon: _saving
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.save),
|
||||
label: Text(_dirty ? 'Sauvegarder' : 'Aucune modification'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _childStatusLabel(String status) {
|
||||
switch (status) {
|
||||
case 'a_naitre':
|
||||
return 'À naître';
|
||||
case 'actif':
|
||||
return 'Actif';
|
||||
case 'scolarise':
|
||||
return 'Scolarisé';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/enfant_admin_model.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_child_detail_modal.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/user_list.dart';
|
||||
|
||||
/// Onglet liste globale des enfants (doc 28 §6.2, ticket #137).
|
||||
class EnfantManagementWidget extends StatefulWidget {
|
||||
final String searchQuery;
|
||||
final String? statusFilter;
|
||||
|
||||
const EnfantManagementWidget({
|
||||
super.key,
|
||||
required this.searchQuery,
|
||||
this.statusFilter,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EnfantManagementWidget> createState() => _EnfantManagementWidgetState();
|
||||
}
|
||||
|
||||
class _EnfantManagementWidgetState extends State<EnfantManagementWidget> {
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
List<EnfantAdminModel> _enfants = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadEnfants();
|
||||
}
|
||||
|
||||
Future<void> _loadEnfants() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final list = await UserService.getEnfants();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_enfants = list;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String _statusLabel(String status) {
|
||||
switch (status) {
|
||||
case 'a_naitre':
|
||||
return 'À naître';
|
||||
case 'actif':
|
||||
return 'Actif';
|
||||
case 'scolarise':
|
||||
return 'Scolarisé';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openEnfant(EnfantAdminModel enfant) async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => AdminChildDetailModal(
|
||||
enfant: enfant,
|
||||
onSaved: _loadEnfants,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = widget.searchQuery.toLowerCase();
|
||||
final filtered = _enfants.where((e) {
|
||||
final matchesName = e.fullName.toLowerCase().contains(query);
|
||||
final matchesStatus =
|
||||
widget.statusFilter == null || e.status == widget.statusFilter;
|
||||
return matchesName && matchesStatus;
|
||||
}).toList();
|
||||
|
||||
return UserList(
|
||||
isLoading: _isLoading,
|
||||
error: _error,
|
||||
isEmpty: filtered.isEmpty,
|
||||
emptyMessage: 'Aucun enfant trouvé.',
|
||||
itemCount: filtered.length,
|
||||
itemBuilder: (context, index) {
|
||||
final enfant = filtered[index];
|
||||
final parents = enfant.parentLinks
|
||||
.map((l) => l.parentName ?? 'Parent')
|
||||
.join(', ');
|
||||
return AdminUserCard(
|
||||
title: enfant.fullName,
|
||||
fallbackIcon: Icons.child_care_outlined,
|
||||
avatarUrl: enfant.photoUrl,
|
||||
subtitleLines: [
|
||||
'Statut : ${_statusLabel(enfant.status)}',
|
||||
if (enfant.birthDate != null && enfant.birthDate!.isNotEmpty)
|
||||
'Naissance : ${enfant.birthDate}',
|
||||
if (parents.isNotEmpty) 'Responsables : $parents',
|
||||
],
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.visibility_outlined),
|
||||
tooltip: 'Voir / modifier',
|
||||
onPressed: () => _openEnfant(enfant),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/parent_model.dart';
|
||||
import 'package:p_tits_pas/utils/phone_utils.dart';
|
||||
import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_detail_modal.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_parent_edit_modal.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/admin_user_card.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/common/user_list.dart';
|
||||
|
||||
@@ -80,7 +79,7 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
avatarUrl: parent.user.photoUrl,
|
||||
subtitleLines: [
|
||||
parent.user.email,
|
||||
'Statut : ${_displayStatus(parent.user.statut)} | Enfants : ${parent.childrenCount}',
|
||||
'Statut : ${_displayStatus(parent.user.statut)} | Enfants : ${parent.children.isNotEmpty ? parent.children.length : parent.childrenCount}',
|
||||
],
|
||||
actions: [
|
||||
IconButton(
|
||||
@@ -114,45 +113,10 @@ class _ParentManagementWidgetState extends State<ParentManagementWidget> {
|
||||
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) != '–' ? formatPhoneForDisplay(_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')),
|
||||
);
|
||||
},
|
||||
builder: (context) => AdminParentEditModal(
|
||||
parent: parent,
|
||||
onSaved: _loadParents,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _v(String? value) => (value == null || value.isEmpty) ? '-' : value;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:p_tits_pas/services/user_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/admin_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/dashboard_admin.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/enfant_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/gestionnaire_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/parent_managmant_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/pending_validation_widget.dart';
|
||||
@@ -28,6 +29,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final TextEditingController _amCapacityController = TextEditingController();
|
||||
String? _parentStatus;
|
||||
String? _enfantStatus;
|
||||
bool _hasPending = false;
|
||||
bool _pendingLoading = true;
|
||||
|
||||
@@ -80,7 +82,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
}
|
||||
|
||||
List<String> get _tabLabels {
|
||||
const base = ['Parents', 'Assistantes maternelles', 'Gestionnaires'];
|
||||
const base = ['Parents', 'Enfants', 'Assistantes maternelles', 'Gestionnaires'];
|
||||
final withAdmin = [...base, 'Administrateurs'];
|
||||
final list = widget.showAdministrateursTab ? withAdmin : base;
|
||||
// Onglet « À valider » visible seulement s'il y a des dossiers en attente (ticket #107).
|
||||
@@ -94,11 +96,12 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
_subIndex = index.clamp(0, maxIndex);
|
||||
_searchController.clear();
|
||||
_parentStatus = null;
|
||||
_enfantStatus = null;
|
||||
_amCapacityController.clear();
|
||||
});
|
||||
}
|
||||
|
||||
/// Index du contenu : -1 = À valider (si visible), 0 = Parents, 1 = AM, 2 = Gestionnaires, 3 = Admin.
|
||||
/// Index du contenu : -1 = À valider, 0 = Parents, 1 = Enfants, 2 = AM, 3 = Gestionnaires, 4 = Admin.
|
||||
int get _contentIndexOffset => (_hasPending && !_pendingLoading) ? 1 : 0;
|
||||
|
||||
String _searchHintForTab() {
|
||||
@@ -109,10 +112,12 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
case 0:
|
||||
return 'Rechercher un parent...';
|
||||
case 1:
|
||||
return 'Rechercher une assistante...';
|
||||
return 'Rechercher un enfant...';
|
||||
case 2:
|
||||
return 'Rechercher un gestionnaire...';
|
||||
return 'Rechercher une assistante...';
|
||||
case 3:
|
||||
return 'Rechercher un gestionnaire...';
|
||||
case 4:
|
||||
return 'Rechercher un administrateur...';
|
||||
default:
|
||||
return 'Rechercher...';
|
||||
@@ -176,6 +181,54 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
}
|
||||
|
||||
if (_subIndex == _contentIndexOffset + 1) {
|
||||
return DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String?>(
|
||||
value: _enfantStatus,
|
||||
isExpanded: true,
|
||||
hint: const Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text('Statut', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem<String?>(
|
||||
value: null,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text('Tous', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
),
|
||||
DropdownMenuItem<String?>(
|
||||
value: 'a_naitre',
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text('À naître', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
),
|
||||
DropdownMenuItem<String?>(
|
||||
value: 'actif',
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text('Actif', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
),
|
||||
DropdownMenuItem<String?>(
|
||||
value: 'scolarise',
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text('Scolarisé', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_enfantStatus = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_subIndex == _contentIndexOffset + 2) {
|
||||
return TextField(
|
||||
controller: _amCapacityController,
|
||||
decoration: const InputDecoration(
|
||||
@@ -203,16 +256,21 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
statusFilter: _parentStatus,
|
||||
);
|
||||
case 1:
|
||||
return EnfantManagementWidget(
|
||||
searchQuery: _searchController.text,
|
||||
statusFilter: _enfantStatus,
|
||||
);
|
||||
case 2:
|
||||
return AssistanteMaternelleManagementWidget(
|
||||
searchQuery: _searchController.text,
|
||||
capacityMin: int.tryParse(_amCapacityController.text),
|
||||
);
|
||||
case 2:
|
||||
case 3:
|
||||
return GestionnaireManagementWidget(
|
||||
key: ValueKey('gestionnaires-$_gestionnaireRefreshTick'),
|
||||
searchQuery: _searchController.text,
|
||||
);
|
||||
case 3:
|
||||
case 4:
|
||||
return AdminManagementWidget(
|
||||
key: ValueKey('admins-$_adminRefreshTick'),
|
||||
searchQuery: _searchController.text,
|
||||
@@ -246,7 +304,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
|
||||
Future<void> _handleAddPressed() async {
|
||||
final contentIndex = _subIndex - _contentIndexOffset;
|
||||
if (contentIndex == 2) {
|
||||
if (contentIndex == 3) {
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -264,7 +322,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (contentIndex == 3) {
|
||||
if (contentIndex == 4) {
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -289,7 +347,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'La création est disponible pour les gestionnaires et administrateurs.',
|
||||
'La création parent / enfant / AM sera disponible avec le ticket #129.',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user