feat(#140): fiches admin famille — IdentityBlock, parsing enfants et avatars web
Extrait IdentityBlock réutilisable, aligne les modales parent/enfant sur le style validation, corrige le parsing parentChildren et les URLs /uploads en Flutter web. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/enfant_admin_model.dart';
|
||||
import 'package:p_tits_pas/utils/phone_utils.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';
|
||||
import 'package:p_tits_pas/widgets/admin/common/validation_detail_section.dart';
|
||||
import 'package:p_tits_pas/widgets/common/identity_block.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/validation_modal_theme.dart';
|
||||
|
||||
/// Fiche parent éditable (doc 28 §6.1, tickets #131 / #138).
|
||||
/// Shell et typo alignés sur [ValidationDossierModal] / wizards validation.
|
||||
class AdminParentEditModal extends StatefulWidget {
|
||||
final ParentModel parent;
|
||||
final VoidCallback? onSaved;
|
||||
@@ -37,6 +41,10 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
|
||||
static const _statuts = ['actif', 'en_attente', 'suspendu', 'refuse'];
|
||||
|
||||
static const double _modalWidth = 930;
|
||||
/// Corps plus haut que les modales validation pour agrandir la liste enfants.
|
||||
static const double _bodyHeight = 580;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -44,20 +52,39 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
_nomCtrl = TextEditingController(text: u.nom ?? '');
|
||||
_prenomCtrl = TextEditingController(text: u.prenom ?? '');
|
||||
_emailCtrl = TextEditingController(text: u.email);
|
||||
_telCtrl = TextEditingController(text: u.telephone ?? '');
|
||||
_telCtrl = TextEditingController(
|
||||
text: formatPhoneForDisplay(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]) {
|
||||
for (final c in [
|
||||
_nomCtrl,
|
||||
_prenomCtrl,
|
||||
_emailCtrl,
|
||||
_telCtrl,
|
||||
_adresseCtrl,
|
||||
_villeCtrl,
|
||||
_cpCtrl,
|
||||
]) {
|
||||
c.addListener(_markDirty);
|
||||
}
|
||||
_reloadChildren();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final c in [_nomCtrl, _prenomCtrl, _emailCtrl, _telCtrl, _adresseCtrl, _villeCtrl, _cpCtrl]) {
|
||||
for (final c in [
|
||||
_nomCtrl,
|
||||
_prenomCtrl,
|
||||
_emailCtrl,
|
||||
_telCtrl,
|
||||
_adresseCtrl,
|
||||
_villeCtrl,
|
||||
_cpCtrl,
|
||||
]) {
|
||||
c.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
@@ -88,10 +115,18 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Confirmer'),
|
||||
content: const Text('Enregistrer les modifications de la fiche parent ?'),
|
||||
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')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('Sauvegarder'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -105,7 +140,7 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
'nom': _nomCtrl.text.trim(),
|
||||
'prenom': _prenomCtrl.text.trim(),
|
||||
'email': _emailCtrl.text.trim(),
|
||||
'telephone': _telCtrl.text.trim(),
|
||||
'telephone': normalizePhone(_telCtrl.text),
|
||||
'adresse': _adresseCtrl.text.trim(),
|
||||
'ville': _villeCtrl.text.trim(),
|
||||
'code_postal': _cpCtrl.text.trim(),
|
||||
@@ -138,9 +173,7 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
context: context,
|
||||
builder: (ctx) => AdminChildDetailModal(
|
||||
enfant: enfant,
|
||||
onSaved: () async {
|
||||
await _reloadChildren();
|
||||
},
|
||||
onSaved: _reloadChildren,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -154,8 +187,26 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
Future<void> _reloadChildren() async {
|
||||
try {
|
||||
final refreshed = await UserService.getParent(widget.parent.user.id);
|
||||
var kids = List.of(refreshed.children);
|
||||
if (kids.any((c) => c.fullName == 'Enfant')) {
|
||||
final all = await UserService.getEnfants();
|
||||
final byId = {for (final e in all) e.id: e};
|
||||
kids = kids
|
||||
.map((c) {
|
||||
if (c.fullName != 'Enfant') return c;
|
||||
final e = byId[c.id];
|
||||
if (e == null) return c;
|
||||
return ParentChildSummary(
|
||||
id: c.id,
|
||||
firstName: e.firstName,
|
||||
lastName: e.lastName,
|
||||
status: c.status.isNotEmpty ? c.status : e.status,
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() => _children = List.of(refreshed.children));
|
||||
setState(() => _children = kids);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -165,13 +216,19 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
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é.)',
|
||||
'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')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.red.shade700),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red.shade700,
|
||||
),
|
||||
child: const Text('Détacher'),
|
||||
),
|
||||
],
|
||||
@@ -254,209 +311,197 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
||||
}
|
||||
}
|
||||
|
||||
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()),
|
||||
),
|
||||
),
|
||||
],
|
||||
Widget _statusDropdown() {
|
||||
return Container(
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: Colors.black26),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _statuts.contains(_statut) ? _statut : _statuts.first,
|
||||
isExpanded: true,
|
||||
isDense: true,
|
||||
style: const TextStyle(fontSize: 13, color: Colors.black87),
|
||||
icon: const Icon(Icons.arrow_drop_down, size: 20),
|
||||
items: _statuts
|
||||
.map(
|
||||
(s) => DropdownMenuItem(
|
||||
value: s,
|
||||
child: Text(_displayStatus(s)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
setState(() {
|
||||
_statut = v;
|
||||
_dirty = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _identityFields() {
|
||||
return IdentityBlock.editable(
|
||||
nomController: _nomCtrl,
|
||||
prenomController: _prenomCtrl,
|
||||
telephoneController: _telCtrl,
|
||||
emailController: _emailCtrl,
|
||||
adresseController: _adresseCtrl,
|
||||
codePostalController: _cpCtrl,
|
||||
villeController: _villeCtrl,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _childrenPanel() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: ValidationFieldDecoration.container(),
|
||||
child: _children.isEmpty
|
||||
? const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Text(
|
||||
'Aucun enfant rattaché',
|
||||
style: TextStyle(fontSize: 14, color: Colors.black54),
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
itemCount: _children.length,
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
height: 1,
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
itemBuilder: (_, i) {
|
||||
final c = _children[i];
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: InkWell(
|
||||
onTap: () => _openChild(c),
|
||||
child: Text(
|
||||
c.fullName,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
_childStatusLabel(c.status),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.black54),
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: 'Détacher',
|
||||
icon: Icon(Icons.link_off, color: Colors.orange.shade800),
|
||||
onPressed: () => _detachChild(c),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFooter() {
|
||||
return Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: _saving ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Fermer'),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton.icon(
|
||||
onPressed: _attachChild,
|
||||
icon: const Icon(Icons.link, size: 18),
|
||||
label: const Text('Rattacher un enfant'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton(
|
||||
style: ValidationModalTheme.primaryElevatedStyle,
|
||||
onPressed: !_dirty || _saving ? null : _save,
|
||||
child: _saving
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Text(_dirty ? 'Sauvegarder' : 'Aucune modification'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final numero = widget.parent.user.numeroDossier;
|
||||
final maxH = MediaQuery.of(context).size.height * 0.85;
|
||||
|
||||
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'),
|
||||
),
|
||||
),
|
||||
],
|
||||
constraints: BoxConstraints(maxWidth: _modalWidth, maxHeight: maxH),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(18, 18, 0, 12),
|
||||
child: Text(
|
||||
'Fiche parent',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(width: 160, child: _statusDropdown()),
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
tooltip: 'Fermer',
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 1),
|
||||
SizedBox(
|
||||
height: _bodyHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_identityFields(),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Nombre d\'enfants : ${_children.length}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(child: _childrenPanel()),
|
||||
const SizedBox(height: 24),
|
||||
_buildFooter(),
|
||||
],
|
||||
),
|
||||
),
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user