feat: WebSocket temps réel + Finance Workflow + corrections

- Task #6: WebSocket /ws/dashboard + Kafka events (5 topics)
  * Backend: KafkaEventProducer, KafkaEventConsumer
  * Mobile: WebSocketService (reconnection, heartbeat, typed events)
  * DashboardBloc: Auto-refresh depuis WebSocket events

- Finance Workflow: approbations + budgets (backend + mobile)
  * Backend: entities, services, resources, migrations Flyway V6
  * Mobile: features finance_workflow complète avec BLoC

- Corrections DI: interfaces IRepository partout
  * IProfileRepository, IOrganizationRepository, IMembreRepository
  * GetIt configuré avec @injectable

- Spec-Kit: constitution + templates mis à jour
  * .specify/memory/constitution.md enrichie
  * Templates agent, plan, spec, tasks, checklist

- Nettoyage: fichiers temporaires supprimés

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 02:12:17 +00:00
parent bbc409de9d
commit e8ad874015
635 changed files with 58160 additions and 20674 deletions

View File

@@ -1,11 +1,13 @@
/// Page détail d'une demande d'aide + actions (approuver, rejeter)
library demande_aide_detail_page;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
import '../../../../shared/widgets/core_card.dart';
import '../../../../shared/widgets/info_badge.dart';
import '../../../../shared/widgets/mini_avatar.dart';
import '../../bloc/solidarity_bloc.dart';
import '../../data/models/demande_aide_model.dart';
import '../../../authentication/presentation/bloc/auth_bloc.dart';
class DemandeAideDetailPage extends StatefulWidget {
final String demandeId;
@@ -28,8 +30,11 @@ class _DemandeAideDetailPageState extends State<DemandeAideDetailPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Détail demande d\'aide'),
backgroundColor: AppColors.background,
appBar: const UFAppBar(
title: 'DÉTAIL DEMANDE',
backgroundColor: AppColors.surface,
foregroundColor: AppColors.textPrimaryLight,
),
body: BlocConsumer<SolidarityBloc, SolidarityState>(
listenWhen: (prev, curr) => prev.status != curr.status,
@@ -91,8 +96,7 @@ class _DemandeAideDetailPageState extends State<DemandeAideDetailPage> {
),
if (d.motif != null && d.motif!.isNotEmpty)
_InfoCard(title: 'Motif', value: d.motif!),
const SizedBox(height: 24),
_ActionsSection(demande: d),
_ActionsSection(demande: d, isGestionnaire: _isGestionnaire()),
],
),
);
@@ -100,36 +104,53 @@ class _DemandeAideDetailPageState extends State<DemandeAideDetailPage> {
),
);
}
bool _isGestionnaire() {
final state = context.read<AuthBloc>().state;
if (state is AuthAuthenticated) {
return state.effectiveRole.level >= 50;
}
return false;
}
}
class _InfoCard extends StatelessWidget {
final String title;
final String value;
final Widget? trail;
const _InfoCard({required this.title, required this.value});
const _InfoCard({required this.title, required this.value, this.trail});
@override
Widget build(BuildContext context) {
return Card(
return CoreCard(
margin: const EdgeInsets.only(bottom: 8),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 120,
child: Text(
title,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.grey[700],
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title.toUpperCase(),
style: AppTypography.subtitleSmall.copyWith(
fontWeight: FontWeight.bold,
fontSize: 9,
color: AppColors.textSecondaryLight,
),
),
),
const SizedBox(height: 2),
Text(
value,
style: AppTypography.bodyTextSmall.copyWith(fontSize: 12),
),
],
),
Expanded(child: Text(value)),
],
),
),
if (trail != null) trail!,
],
),
);
}
@@ -137,11 +158,14 @@ class _InfoCard extends StatelessWidget {
class _ActionsSection extends StatelessWidget {
final DemandeAideModel demande;
final bool isGestionnaire;
const _ActionsSection({required this.demande});
const _ActionsSection({required this.demande, required this.isGestionnaire});
@override
Widget build(BuildContext context) {
if (!isGestionnaire) return const SizedBox.shrink();
final bloc = context.read<SolidarityBloc>();
if (demande.statut != 'EN_ATTENTE' && demande.statut != 'SOUMISE') {
return const SizedBox.shrink();
@@ -150,30 +174,83 @@ class _ActionsSection extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Actions (admin)',
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
ElevatedButton.icon(
onPressed: () => bloc.add(ApprouverDemandeAide(demande.id!)),
icon: const Icon(Icons.check_circle),
label: const Text('Approuver'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(
'ACTIONS ADMINISTRATIVES',
style: AppTypography.subtitleSmall.copyWith(
fontWeight: FontWeight.bold,
letterSpacing: 1.1,
),
),
),
const SizedBox(height: 8),
OutlinedButton.icon(
onPressed: () => bloc.add(RejeterDemandeAide(demande.id!)),
icon: const Icon(Icons.cancel),
label: const Text('Rejeter'),
style: OutlinedButton.styleFrom(foregroundColor: Colors.red),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => bloc.add(ApprouverDemandeAide(demande.id!)),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.success,
foregroundColor: Colors.white,
elevation: 0,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
child: Text('APPROUVER', style: AppTypography.actionText.copyWith(fontSize: 11, color: Colors.white)),
),
),
const SizedBox(width: 12),
Expanded(
child: OutlinedButton(
onPressed: () => _showRejetDialog(context, demande.id!, bloc),
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.error,
side: const BorderSide(color: AppColors.error),
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
child: Text('REJETER', style: AppTypography.actionText.copyWith(fontSize: 11)),
),
),
],
),
],
);
}
void _showRejetDialog(BuildContext context, String demandeId, SolidarityBloc bloc) {
final motifController = TextEditingController();
showDialog<void>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Rejeter la demande'),
content: TextField(
controller: motifController,
decoration: const InputDecoration(
labelText: 'Motif du rejet (recommandé pour traçabilité)',
hintText: 'Saisir le motif...',
border: OutlineInputBorder(),
),
maxLines: 3,
autofocus: true,
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Annuler'),
),
FilledButton(
onPressed: () {
final motif = motifController.text.trim();
Navigator.pop(ctx);
bloc.add(RejeterDemandeAide(demandeId, motif: motif.isNotEmpty ? motif : null));
},
style: FilledButton.styleFrom(backgroundColor: AppColors.error),
child: const Text('Rejeter'),
),
],
),
);
}
}

View File

@@ -1,14 +1,17 @@
/// Page liste des demandes d'aide (solidarité)
library demandes_aide_page;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
import '../../../../shared/widgets/core_card.dart';
import '../../../../shared/widgets/info_badge.dart';
import '../../../../shared/widgets/mini_avatar.dart';
import '../../bloc/solidarity_bloc.dart';
import '../../data/models/demande_aide_model.dart';
import 'demande_aide_detail_page.dart';
import '../widgets/create_demande_aide_dialog.dart';
import '../../../authentication/presentation/bloc/auth_bloc.dart';
/// Page liste des demandes d'aide (solidarité) - Version Épurée
class DemandesAidePage extends StatefulWidget {
const DemandesAidePage({super.key});
@@ -19,13 +22,13 @@ class DemandesAidePage extends StatefulWidget {
class _DemandesAidePageState extends State<DemandesAidePage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA');
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA', decimalDigits: 0);
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
context.read<SolidarityBloc>().add(const LoadDemandesAide());
_loadTab(0);
}
@override
@@ -35,16 +38,27 @@ class _DemandesAidePageState extends State<DemandesAidePage>
}
void _loadTab(int index) {
switch (index) {
case 0:
context.read<SolidarityBloc>().add(const LoadDemandesAide());
break;
case 1:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'EN_ATTENTE'));
break;
case 2:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'APPROUVEE'));
break;
bool isGestionnaire = false;
final authState = context.read<AuthBloc>().state;
if (authState is AuthAuthenticated) {
isGestionnaire = authState.effectiveRole.level >= 50;
}
if (isGestionnaire) {
switch (index) {
case 0:
context.read<SolidarityBloc>().add(const SearchDemandesAide()); // Search sans statut = getAll
break;
case 1:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'EN_ATTENTE'));
break;
case 2:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'APPROUVEE'));
break;
}
} else {
// Normal member always fetches their own requests
context.read<SolidarityBloc>().add(const LoadDemandesAide());
}
}
@@ -55,44 +69,41 @@ class _DemandesAidePageState extends State<DemandesAidePage>
if (state.status == SolidarityStatus.error && state.message != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message!),
backgroundColor: Colors.red,
action: SnackBarAction(
label: 'Réessayer',
textColor: Colors.white,
onPressed: () => _loadTab(_tabController.index),
),
content: Text(state.message!,
style: AppTypography.bodyTextSmall.copyWith(color: Colors.white)),
backgroundColor: AppColors.error,
),
);
}
},
child: Scaffold(
appBar: AppBar(
title: const Text('Demandes d\'aide'),
backgroundColor: AppColors.background,
appBar: UFAppBar(
title: 'SOLIDARITÉ',
backgroundColor: AppColors.surface,
foregroundColor: AppColors.textPrimaryLight,
bottom: TabBar(
controller: _tabController,
onTap: _loadTab,
labelColor: AppColors.primaryGreen,
unselectedLabelColor: AppColors.textSecondaryLight,
indicatorColor: AppColors.primaryGreen,
indicatorSize: TabBarIndicatorSize.label,
labelStyle: AppTypography.actionText.copyWith(fontSize: 10, fontWeight: FontWeight.bold),
tabs: const [
Tab(text: 'Toutes', icon: Icon(Icons.list)),
Tab(text: 'En attente', icon: Icon(Icons.schedule)),
Tab(text: 'Approuvées', icon: Icon(Icons.check_circle_outline)),
Tab(child: Text('TOUTES')),
Tab(child: Text('ATTENTE')),
Tab(child: Text('APPROUVÉES')),
],
),
actions: [
IconButton(
icon: const Icon(Icons.add),
onPressed: () => _showCreateDialog(),
tooltip: 'Nouvelle demande',
),
],
),
body: TabBarView(
controller: _tabController,
children: [
_buildList(null),
_buildList('EN_ATTENTE'),
_buildList('APPROUVEE'),
],
controller: _tabController,
children: [
_buildList(null),
_buildList('EN_ATTENTE'),
_buildList('APPROUVEE'),
],
),
),
);
@@ -104,7 +115,7 @@ class _DemandesAidePageState extends State<DemandesAidePage>
prev.status != curr.status || prev.demandes != curr.demandes,
builder: (context, state) {
if (state.status == SolidarityStatus.loading && state.demandes.isEmpty) {
return const Center(child: CircularProgressIndicator());
return const Center(child: CircularProgressIndicator(strokeWidth: 2));
}
var list = state.demandes;
if (statutFilter != null) {
@@ -115,18 +126,9 @@ class _DemandesAidePageState extends State<DemandesAidePage>
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.volunteer_activism, size: 64, color: Colors.grey[400]),
const SizedBox(height: 16),
Text(
'Aucune demande d\'aide',
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
),
const SizedBox(height: 8),
TextButton.icon(
onPressed: () => _showCreateDialog(),
icon: const Icon(Icons.add),
label: const Text('Créer une demande'),
),
const Icon(Icons.volunteer_activism_outlined, size: 32, color: AppColors.lightBorder),
const SizedBox(height: 12),
Text('Aucune demande', style: AppTypography.subtitleSmall),
],
),
);
@@ -134,14 +136,13 @@ class _DemandesAidePageState extends State<DemandesAidePage>
return RefreshIndicator(
onRefresh: () async => _loadTab(_tabController.index),
child: ListView.builder(
padding: const EdgeInsets.all(8),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
itemCount: list.length,
itemBuilder: (context, index) {
final d = list[index];
return _DemandeCard(
demande: d,
demande: list[index],
currencyFormat: _currencyFormat,
onTap: () => _openDetail(d),
onTap: () => _openDetail(list[index]),
);
},
),
@@ -161,18 +162,6 @@ class _DemandesAidePageState extends State<DemandesAidePage>
),
).then((_) => _loadTab(_tabController.index));
}
void _showCreateDialog() {
showDialog<void>(
context: context,
builder: (context) => CreateDemandeAideDialog(
onCreated: () {
Navigator.of(context).pop();
_loadTab(_tabController.index);
},
),
);
}
}
class _DemandeCard extends StatelessWidget {
@@ -188,98 +177,81 @@ class _DemandeCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
margin: const EdgeInsets.only(bottom: 8),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
return CoreCard(
margin: const EdgeInsets.only(bottom: 10),
onTap: onTap,
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Row(
children: [
Expanded(
child: Text(
demande.titre ?? demande.numeroReference ?? demande.id ?? '',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
const MiniAvatar(size: 24, fallbackText: '?'),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
demande.titre ?? 'Demande sans titre',
style: AppTypography.actionText.copyWith(fontSize: 12),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
_StatutChip(statut: demande.statut),
],
Text(
demande.numeroReference ?? demande.id?.substring(0, 8) ?? '',
style: AppTypography.subtitleSmall.copyWith(fontSize: 9),
),
],
),
),
const SizedBox(height: 4),
if (demande.type != null)
Text(
demande.typeLibelle,
style: theme.textTheme.bodySmall?.copyWith(color: Colors.grey[600]),
),
if (demande.montantDemande != null && demande.montantDemande! > 0) ...[
const SizedBox(height: 4),
Text(
currencyFormat.format(demande.montantDemande),
style: theme.textTheme.titleSmall?.copyWith(
color: theme.colorScheme.primary,
),
),
],
if (demande.dateDemande != null) ...[
const SizedBox(height: 4),
Text(
DateFormat('dd/MM/yyyy').format(demande.dateDemande!),
style: theme.textTheme.bodySmall,
),
],
_buildStatutBadge(demande.statut),
],
),
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('MONTANT DEMANDÉ', style: AppTypography.subtitleSmall.copyWith(fontSize: 8, fontWeight: FontWeight.bold)),
Text(
currencyFormat.format(demande.montantDemande ?? 0),
style: AppTypography.headerSmall.copyWith(fontSize: 13, color: AppColors.primaryGreen),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text('TYPE', style: AppTypography.subtitleSmall.copyWith(fontSize: 8, fontWeight: FontWeight.bold)),
Text(demande.typeLibelle, style: AppTypography.bodyTextSmall.copyWith(fontSize: 10)),
],
),
],
),
],
),
);
}
}
class _StatutChip extends StatelessWidget {
final String? statut;
const _StatutChip({this.statut});
@override
Widget build(BuildContext context) {
Widget _buildStatutBadge(String? statut) {
Color color;
switch (statut) {
case 'BROUILLON':
color = Colors.grey;
break;
case 'SOUMISE':
case 'EN_ATTENTE':
color = Colors.orange;
break;
case 'APPROUVEE':
color = Colors.green;
color = AppColors.success;
break;
case 'REJETEE':
color = Colors.red;
color = AppColors.error;
break;
case 'TERMINEE':
color = Colors.blue;
case 'EN_ATTENTE':
case 'SOUMISE':
color = AppColors.brandGreenLight;
break;
default:
color = Colors.grey;
color = AppColors.textSecondaryLight;
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: color.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Text(
statut ?? '',
style: TextStyle(fontSize: 12, color: color, fontWeight: FontWeight.w500),
),
);
return InfoBadge(text: statut ?? 'INCONNU', backgroundColor: color);
}
}

View File

@@ -4,10 +4,13 @@ library create_demande_aide_dialog;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import '../../../../core/utils/logger.dart';
import '../../bloc/solidarity_bloc.dart';
import '../../data/models/demande_aide_model.dart';
import '../../../organizations/data/repositories/organization_repository.dart';
import '../../../organizations/domain/repositories/organization_repository.dart';
import '../../../organizations/data/models/organization_model.dart';
import '../../../members/data/models/membre_complete_model.dart';
import '../../../profile/domain/repositories/profile_repository.dart';
class CreateDemandeAideDialog extends StatefulWidget {
final VoidCallback onCreated;
@@ -28,6 +31,8 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
String? _type;
List<OrganizationModel> _organisations = [];
bool _loading = false;
bool _isInitLoading = true;
MembreCompletModel? _me;
static const List<Map<String, String>> _types = [
{'value': 'FINANCIERE', 'label': 'Financière'},
@@ -42,7 +47,32 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
@override
void initState() {
super.initState();
_loadOrgs();
_loadInitialData();
}
Future<void> _loadInitialData() async {
try {
final user = await GetIt.instance<IProfileRepository>().getMe();
final orgRepo = GetIt.instance<IOrganizationRepository>();
final list = await orgRepo.getOrganizations(page: 0, size: 100);
if (mounted) {
setState(() {
_me = user;
_organisations = list;
_isInitLoading = false;
});
}
} catch (e, st) {
AppLogger.error('CreateDemandeAideDialog: chargement données initiales échoué', error: e, stackTrace: st);
if (mounted) {
setState(() {
_isInitLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Impossible de charger le profil ou les organisations. Réessayez.')),
);
}
}
}
@override
@@ -54,17 +84,13 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
super.dispose();
}
Future<void> _loadOrgs() async {
try {
final repo = GetIt.instance<OrganizationRepository>();
final list = await repo.getOrganizations(page: 0, size: 100);
if (mounted) setState(() => _organisations = list);
} catch (_) {
if (mounted) setState(() {});
}
}
void _submit() {
if (_me == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Profil non chargé, veuillez réessayer')),
);
return;
}
if (!_formKey.currentState!.validate()) return;
final titre = _titreController.text.trim();
final description = _descriptionController.text.trim();
@@ -85,6 +111,7 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
type: _type,
montantDemande: montant,
organisationId: _organisationId,
demandeurId: _me!.id,
dateDemande: DateTime.now(),
statut: 'BROUILLON',
);
@@ -106,6 +133,21 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_isInitLoading)
const CircularProgressIndicator()
else if (_me != null)
TextFormField(
initialValue: '${_me!.prenom} ${_me!.nom}',
decoration: const InputDecoration(
labelText: 'Demandeur',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.person),
),
enabled: false,
)
else
const Text('Impossible de récupérer votre profil', style: TextStyle(color: Colors.red)),
const SizedBox(height: 12),
TextFormField(
controller: _titreController,
decoration: const InputDecoration(
@@ -164,6 +206,7 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
const SizedBox(height: 12),
DropdownButtonFormField<String>(
value: _organisationId,
isExpanded: true,
decoration: const InputDecoration(
labelText: 'Organisation',
border: OutlineInputBorder(),
@@ -171,7 +214,7 @@ class _CreateDemandeAideDialogState extends State<CreateDemandeAideDialog> {
items: _organisations
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.nom),
child: Text(o.nom, overflow: TextOverflow.ellipsis, maxLines: 1),
))
.toList(),
onChanged: _loading ? null : (v) => setState(() => _organisationId = v),