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:
@@ -3,12 +3,14 @@ library solidarity_bloc;
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../data/models/demande_aide_model.dart';
|
||||
import '../data/repositories/demande_aide_repository.dart';
|
||||
|
||||
part 'solidarity_event.dart';
|
||||
part 'solidarity_state.dart';
|
||||
|
||||
@injectable
|
||||
class SolidarityBloc extends Bloc<SolidarityEvent, SolidarityState> {
|
||||
final DemandeAideRepository _repository;
|
||||
|
||||
@@ -24,7 +26,7 @@ class SolidarityBloc extends Bloc<SolidarityEvent, SolidarityState> {
|
||||
Future<void> _onLoadDemandesAide(LoadDemandesAide event, Emitter<SolidarityState> emit) async {
|
||||
emit(state.copyWith(status: SolidarityStatus.loading, message: 'Chargement...'));
|
||||
try {
|
||||
final list = await _repository.getAll(page: event.page, size: event.size);
|
||||
final list = await _repository.getMesDemandes(page: event.page, size: event.size);
|
||||
emit(state.copyWith(status: SolidarityStatus.loaded, demandes: list));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(status: SolidarityStatus.error, message: e.toString(), error: e));
|
||||
@@ -80,7 +82,7 @@ class SolidarityBloc extends Bloc<SolidarityEvent, SolidarityState> {
|
||||
Future<void> _onRejeterDemandeAide(RejeterDemandeAide event, Emitter<SolidarityState> emit) async {
|
||||
emit(state.copyWith(status: SolidarityStatus.loading));
|
||||
try {
|
||||
final updated = await _repository.rejeter(event.id);
|
||||
final updated = await _repository.rejeter(event.id, motif: event.motif);
|
||||
emit(state.copyWith(status: SolidarityStatus.loaded, demandeDetail: updated));
|
||||
add(const LoadDemandesAide());
|
||||
} catch (e) {
|
||||
|
||||
@@ -47,7 +47,8 @@ class ApprouverDemandeAide extends SolidarityEvent {
|
||||
|
||||
class RejeterDemandeAide extends SolidarityEvent {
|
||||
final String id;
|
||||
const RejeterDemandeAide(this.id);
|
||||
final String? motif;
|
||||
const RejeterDemandeAide(this.id, {this.motif});
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
List<Object?> get props => [id, motif];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
part of 'demande_aide_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DemandeAideModel _$DemandeAideModelFromJson(Map<String, dynamic> json) =>
|
||||
DemandeAideModel(
|
||||
id: json['id'] as String?,
|
||||
|
||||
@@ -4,15 +4,19 @@
|
||||
library demande_aide_repository;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import '../models/demande_aide_model.dart';
|
||||
|
||||
abstract class DemandeAideRepository {
|
||||
/// Demandes du membre connecté (GET /api/demandes-aide/mes)
|
||||
Future<List<DemandeAideModel>> getMesDemandes({int page = 0, int size = 50});
|
||||
Future<List<DemandeAideModel>> getAll({int page = 0, int size = 20});
|
||||
Future<DemandeAideModel?> getById(String id);
|
||||
Future<DemandeAideModel> create(DemandeAideModel demande);
|
||||
Future<DemandeAideModel> update(String id, DemandeAideModel demande);
|
||||
Future<DemandeAideModel> approuver(String id);
|
||||
Future<DemandeAideModel> rejeter(String id);
|
||||
Future<DemandeAideModel> rejeter(String id, {String? motif});
|
||||
Future<List<DemandeAideModel>> search({
|
||||
String? statut,
|
||||
String? type,
|
||||
@@ -22,15 +26,29 @@ abstract class DemandeAideRepository {
|
||||
});
|
||||
}
|
||||
|
||||
@LazySingleton(as: DemandeAideRepository)
|
||||
class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
final Dio _dio;
|
||||
final ApiClient _apiClient;
|
||||
static const String _base = '/api/demandes-aide';
|
||||
|
||||
DemandeAideRepositoryImpl(this._dio);
|
||||
DemandeAideRepositoryImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<List<DemandeAideModel>> getMesDemandes({int page = 0, int size = 50}) async {
|
||||
final response = await _apiClient.get(
|
||||
'$_base/mes',
|
||||
queryParameters: {'page': page, 'size': size},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = response.data is List ? response.data : [];
|
||||
return data.map((e) => DemandeAideModel.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
throw Exception('Erreur ${response.statusCode}');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DemandeAideModel>> getAll({int page = 0, int size = 20}) async {
|
||||
final response = await _dio.get(
|
||||
final response = await _apiClient.get(
|
||||
_base,
|
||||
queryParameters: {'page': page, 'size': size},
|
||||
);
|
||||
@@ -45,7 +63,7 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
|
||||
@override
|
||||
Future<DemandeAideModel?> getById(String id) async {
|
||||
final response = await _dio.get('$_base/$id');
|
||||
final response = await _apiClient.get('$_base/$id');
|
||||
if (response.statusCode == 200) {
|
||||
return DemandeAideModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
@@ -55,7 +73,7 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
|
||||
@override
|
||||
Future<DemandeAideModel> create(DemandeAideModel demande) async {
|
||||
final response = await _dio.post(_base, data: demande.toJson());
|
||||
final response = await _apiClient.post(_base, data: demande.toJson());
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return DemandeAideModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
@@ -64,7 +82,7 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
|
||||
@override
|
||||
Future<DemandeAideModel> update(String id, DemandeAideModel demande) async {
|
||||
final response = await _dio.put('$_base/$id', data: demande.toJson());
|
||||
final response = await _apiClient.put('$_base/$id', data: demande.toJson());
|
||||
if (response.statusCode == 200) {
|
||||
return DemandeAideModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
@@ -73,7 +91,7 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
|
||||
@override
|
||||
Future<DemandeAideModel> approuver(String id) async {
|
||||
final response = await _dio.put('$_base/$id/approuver');
|
||||
final response = await _apiClient.put('$_base/$id/approuver');
|
||||
if (response.statusCode == 200) {
|
||||
return DemandeAideModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
@@ -81,8 +99,11 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DemandeAideModel> rejeter(String id) async {
|
||||
final response = await _dio.put('$_base/$id/rejeter');
|
||||
Future<DemandeAideModel> rejeter(String id, {String? motif}) async {
|
||||
final response = await _apiClient.put(
|
||||
'$_base/$id/rejeter',
|
||||
data: motif != null && motif.isNotEmpty ? {'motif': motif} : null,
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return DemandeAideModel.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
@@ -101,7 +122,7 @@ class DemandeAideRepositoryImpl implements DemandeAideRepository {
|
||||
if (statut != null) q['statut'] = statut;
|
||||
if (type != null) q['type'] = type;
|
||||
if (urgence != null) q['urgence'] = urgence;
|
||||
final response = await _dio.get('$_base/search', queryParameters: q);
|
||||
final response = await _apiClient.get('$_base/search', queryParameters: q);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = response.data is List ? response.data : (response.data as Map)['content'] as List? ?? [];
|
||||
return data
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/// Configuration de l'injection de dépendances pour le module Solidarité (demandes d'aide)
|
||||
library solidarity_di;
|
||||
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../bloc/solidarity_bloc.dart';
|
||||
import '../data/repositories/demande_aide_repository.dart';
|
||||
|
||||
void registerSolidarityDependencies(GetIt getIt) {
|
||||
getIt.registerLazySingleton<DemandeAideRepository>(
|
||||
() => DemandeAideRepositoryImpl(getIt<Dio>()),
|
||||
);
|
||||
getIt.registerFactory<SolidarityBloc>(
|
||||
() => SolidarityBloc(getIt<DemandeAideRepository>()),
|
||||
);
|
||||
}
|
||||
@@ -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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user