feat(unionflow): ajout Spec-Kit, constitution, mission mutuelles
- Config Spec-Kit pour Spec-Driven Development - CONSTITUTION.md + .specify/memory/constitution.md - Commandes Cursor /speckit.*, règles projet - Mission: associations + mutuelles d'épargne et de financement - .gitignore: versionner config spec-kit unionflow Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
/// Page détail d'une demande d'adhésion + actions (approuver, rejeter, paiement)
|
||||
library adhesion_detail_page;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
import '../../data/models/adhesion_model.dart';
|
||||
import '../widgets/paiement_adhesion_dialog.dart';
|
||||
import '../widgets/rejet_adhesion_dialog.dart';
|
||||
|
||||
class AdhesionDetailPage extends StatefulWidget {
|
||||
final String adhesionId;
|
||||
|
||||
const AdhesionDetailPage({super.key, required this.adhesionId});
|
||||
|
||||
@override
|
||||
State<AdhesionDetailPage> createState() => _AdhesionDetailPageState();
|
||||
}
|
||||
|
||||
class _AdhesionDetailPageState extends State<AdhesionDetailPage> {
|
||||
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA');
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
context.read<AdhesionsBloc>().add(LoadAdhesionById(widget.adhesionId));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Détail adhésion'),
|
||||
),
|
||||
body: BlocConsumer<AdhesionsBloc, AdhesionsState>(
|
||||
listenWhen: (prev, curr) => prev.status != curr.status,
|
||||
listener: (context, state) {
|
||||
if (state.status == AdhesionsStatus.error && state.message != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message!), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
},
|
||||
buildWhen: (prev, curr) =>
|
||||
prev.adhesionDetail != curr.adhesionDetail || prev.status != curr.status,
|
||||
builder: (context, state) {
|
||||
if (state.status == AdhesionsStatus.loading && state.adhesionDetail == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final a = state.adhesionDetail;
|
||||
if (a == null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline, size: 64, color: Colors.grey),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Adhésion introuvable',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_InfoCard(
|
||||
title: 'Référence',
|
||||
value: a.numeroReference ?? a.id ?? '—',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_InfoCard(title: 'Statut', value: a.statutLibelle),
|
||||
const SizedBox(height: 12),
|
||||
_InfoCard(
|
||||
title: 'Organisation',
|
||||
value: a.nomOrganisation ?? a.organisationId ?? '—',
|
||||
),
|
||||
_InfoCard(
|
||||
title: 'Membre',
|
||||
value: a.nomMembreComplet,
|
||||
),
|
||||
if (a.emailMembre != null && a.emailMembre!.isNotEmpty)
|
||||
_InfoCard(title: 'Email', value: a.emailMembre!),
|
||||
if (a.dateDemande != null)
|
||||
_InfoCard(
|
||||
title: 'Date demande',
|
||||
value: DateFormat('dd/MM/yyyy').format(a.dateDemande!),
|
||||
),
|
||||
_InfoCard(
|
||||
title: 'Frais d\'adhésion',
|
||||
value: a.fraisAdhesion != null
|
||||
? _currencyFormat.format(a.fraisAdhesion)
|
||||
: '—',
|
||||
),
|
||||
if (a.montantPaye != null && a.montantPaye! > 0)
|
||||
_InfoCard(
|
||||
title: 'Montant payé',
|
||||
value: _currencyFormat.format(a.montantPaye!),
|
||||
),
|
||||
if (a.montantRestant > 0)
|
||||
_InfoCard(
|
||||
title: 'Montant restant',
|
||||
value: _currencyFormat.format(a.montantRestant),
|
||||
),
|
||||
if (a.motifRejet != null && a.motifRejet!.isNotEmpty)
|
||||
_InfoCard(title: 'Motif rejet', value: a.motifRejet!),
|
||||
const SizedBox(height: 24),
|
||||
_ActionsSection(adhesion: a, currencyFormat: _currencyFormat),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoCard extends StatelessWidget {
|
||||
final String title;
|
||||
final String value;
|
||||
|
||||
const _InfoCard({required this.title, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
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],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: Text(value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActionsSection extends StatelessWidget {
|
||||
final AdhesionModel adhesion;
|
||||
final NumberFormat currencyFormat;
|
||||
|
||||
const _ActionsSection({
|
||||
required this.adhesion,
|
||||
required this.currencyFormat,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bloc = context.read<AdhesionsBloc>();
|
||||
if (adhesion.statut == 'EN_ATTENTE') {
|
||||
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: () {
|
||||
if (adhesion.id == null) return;
|
||||
bloc.add(ApprouverAdhesion(adhesion.id!));
|
||||
},
|
||||
icon: const Icon(Icons.check_circle),
|
||||
label: const Text('Approuver'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
if (adhesion.id == null) return;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => BlocProvider.value(
|
||||
value: bloc,
|
||||
child: RejetAdhesionDialog(
|
||||
adhesionId: adhesion.id!,
|
||||
onRejected: () => Navigator.of(ctx).pop(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.cancel),
|
||||
label: const Text('Rejeter'),
|
||||
style: OutlinedButton.styleFrom(foregroundColor: Colors.red),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (adhesion.estEnAttentePaiement && adhesion.id != null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'Paiement',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => BlocProvider.value(
|
||||
value: bloc,
|
||||
child: PaiementAdhesionDialog(
|
||||
adhesionId: adhesion.id!,
|
||||
montantRestant: adhesion.montantRestant,
|
||||
onPaid: () => Navigator.of(ctx).pop(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.payment),
|
||||
label: const Text('Enregistrer un paiement'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
/// Page liste des demandes d'adhésion
|
||||
library adhesions_page;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
import '../../data/models/adhesion_model.dart';
|
||||
import 'adhesion_detail_page.dart';
|
||||
import '../widgets/create_adhesion_dialog.dart';
|
||||
|
||||
class AdhesionsPage extends StatefulWidget {
|
||||
const AdhesionsPage({super.key});
|
||||
|
||||
@override
|
||||
State<AdhesionsPage> createState() => _AdhesionsPageState();
|
||||
}
|
||||
|
||||
class _AdhesionsPageState extends State<AdhesionsPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA');
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
context.read<AdhesionsBloc>().add(const LoadAdhesions());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadTab(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
context.read<AdhesionsBloc>().add(const LoadAdhesions());
|
||||
break;
|
||||
case 1:
|
||||
context.read<AdhesionsBloc>().add(const LoadAdhesionsEnAttente());
|
||||
break;
|
||||
case 2:
|
||||
context.read<AdhesionsBloc>().add(const LoadAdhesionsByStatut('APPROUVEE'));
|
||||
break;
|
||||
case 3:
|
||||
context.read<AdhesionsBloc>().add(const LoadAdhesionsByStatut('PAYEE'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<AdhesionsBloc, AdhesionsState>(
|
||||
listener: (context, state) {
|
||||
if (state.status == AdhesionsStatus.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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Demandes d\'adhésion'),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
onTap: _loadTab,
|
||||
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(text: 'Payées', icon: Icon(Icons.payment)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () => _showCreateDialog(),
|
||||
tooltip: 'Nouvelle demande',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildList(null),
|
||||
_buildList('EN_ATTENTE'),
|
||||
_buildList('APPROUVEE'), // tab 2 charge déjà par statut
|
||||
_buildList('PAYEE'), // tab 3 charge déjà par statut
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(String? statutFilter) {
|
||||
return BlocBuilder<AdhesionsBloc, AdhesionsState>(
|
||||
buildWhen: (prev, curr) =>
|
||||
prev.status != curr.status || prev.adhesions != curr.adhesions,
|
||||
builder: (context, state) {
|
||||
if (state.status == AdhesionsStatus.loading && state.adhesions.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
var list = state.adhesions;
|
||||
if (statutFilter != null) {
|
||||
list = list.where((a) => a.statut == statutFilter).toList();
|
||||
}
|
||||
if (list.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.assignment_outlined, size: 64, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucune demande d\'adhésion',
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => _loadTab(_tabController.index),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: list.length,
|
||||
itemBuilder: (context, index) {
|
||||
final a = list[index];
|
||||
return _AdhesionCard(
|
||||
adhesion: a,
|
||||
currencyFormat: _currencyFormat,
|
||||
onTap: () => _openDetail(a),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _openDetail(AdhesionModel a) {
|
||||
if (a.id == null) return;
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: context.read<AdhesionsBloc>(),
|
||||
child: AdhesionDetailPage(adhesionId: a.id!),
|
||||
),
|
||||
),
|
||||
).then((_) => _loadTab(_tabController.index));
|
||||
}
|
||||
|
||||
void _showCreateDialog() {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CreateAdhesionDialog(
|
||||
onCreated: () {
|
||||
Navigator.of(context).pop();
|
||||
_loadTab(_tabController.index);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AdhesionCard extends StatelessWidget {
|
||||
final AdhesionModel adhesion;
|
||||
final NumberFormat currencyFormat;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _AdhesionCard({
|
||||
required this.adhesion,
|
||||
required this.currencyFormat,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@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,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
adhesion.numeroReference ?? adhesion.id ?? '—',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
_StatutChip(statut: adhesion.statut),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
adhesion.nomOrganisation ?? adhesion.organisationId ?? 'Organisation',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
if (adhesion.nomMembreComplet.isNotEmpty)
|
||||
Text(
|
||||
adhesion.nomMembreComplet,
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
adhesion.fraisAdhesion != null
|
||||
? currencyFormat.format(adhesion.fraisAdhesion)
|
||||
: '—',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
if (adhesion.dateDemande != null) ...[
|
||||
const Spacer(),
|
||||
Text(
|
||||
DateFormat('dd/MM/yyyy').format(adhesion.dateDemande!),
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatutChip extends StatelessWidget {
|
||||
final String? statut;
|
||||
|
||||
const _StatutChip({this.statut});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color color;
|
||||
switch (statut) {
|
||||
case 'EN_ATTENTE':
|
||||
color = Colors.orange;
|
||||
break;
|
||||
case 'APPROUVEE':
|
||||
case 'PAYEE':
|
||||
color = Colors.green;
|
||||
break;
|
||||
case 'REJETEE':
|
||||
color = Colors.red;
|
||||
break;
|
||||
case 'ANNULEE':
|
||||
color = Colors.grey;
|
||||
break;
|
||||
case 'EN_PAIEMENT':
|
||||
color = Colors.blue;
|
||||
break;
|
||||
default:
|
||||
color = Colors.grey;
|
||||
}
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/// Wrapper BLoC pour la page des adhésions
|
||||
library adhesions_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
import 'adhesions_page.dart';
|
||||
|
||||
final _getIt = GetIt.instance;
|
||||
|
||||
class AdhesionsPageWrapper extends StatelessWidget {
|
||||
const AdhesionsPageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<AdhesionsBloc>(
|
||||
create: (context) {
|
||||
final bloc = _getIt<AdhesionsBloc>();
|
||||
bloc.add(const LoadAdhesions());
|
||||
return bloc;
|
||||
},
|
||||
child: const AdhesionsPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/// Dialog de création d'une demande d'adhésion
|
||||
library create_adhesion_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
import '../../data/models/adhesion_model.dart';
|
||||
import '../../../organizations/data/models/organization_model.dart';
|
||||
import '../../../organizations/data/repositories/organization_repository.dart';
|
||||
import '../../../members/data/services/membre_search_service.dart';
|
||||
import '../../../members/data/models/membre_complete_model.dart';
|
||||
|
||||
class CreateAdhesionDialog extends StatefulWidget {
|
||||
final VoidCallback onCreated;
|
||||
|
||||
const CreateAdhesionDialog({super.key, required this.onCreated});
|
||||
|
||||
@override
|
||||
State<CreateAdhesionDialog> createState() => _CreateAdhesionDialogState();
|
||||
}
|
||||
|
||||
class _CreateAdhesionDialogState extends State<CreateAdhesionDialog> {
|
||||
final _fraisController = TextEditingController();
|
||||
String? _membreId;
|
||||
String? _organisationId;
|
||||
bool _loading = false;
|
||||
List<OrganizationModel> _organisations = [];
|
||||
List<MembreCompletModel> _membres = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadOrgs();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_fraisController.dispose();
|
||||
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(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _searchMembres(String query) async {
|
||||
if (query.length < 2) {
|
||||
setState(() => _membres = []);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final service = GetIt.instance<MembreSearchService>();
|
||||
final result = await service.quickSearch(query: query, size: 20);
|
||||
if (mounted) setState(() => _membres = result.membres);
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _membres = []);
|
||||
}
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (_membreId == null || _organisationId == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Veuillez sélectionner un membre et une organisation')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final frais = double.tryParse(_fraisController.text.replaceAll(',', '.'));
|
||||
if (frais == null || frais <= 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Frais d\'adhésion invalides')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _loading = true);
|
||||
final adhesion = AdhesionModel(
|
||||
membreId: _membreId,
|
||||
organisationId: _organisationId,
|
||||
fraisAdhesion: frais,
|
||||
codeDevise: 'XOF',
|
||||
dateDemande: DateTime.now(),
|
||||
);
|
||||
context.read<AdhesionsBloc>().add(CreateAdhesion(adhesion));
|
||||
widget.onCreated();
|
||||
if (mounted) {
|
||||
setState(() => _loading = false);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Nouvelle demande d\'adhésion'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Rechercher un membre (nom, prénom)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onChanged: _searchMembres,
|
||||
enabled: !_loading,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _membreId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Membre',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: _membres
|
||||
.map((m) => DropdownMenuItem<String>(
|
||||
value: m.id,
|
||||
child: Text('${m.prenom} ${m.nom}'),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: _loading ? null : (v) => setState(() => _membreId = v),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _organisationId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Organisation',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: _organisations
|
||||
.map((o) => DropdownMenuItem<String>(
|
||||
value: o.id,
|
||||
child: Text(o.nom),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: _loading ? null : (v) => setState(() => _organisationId = v),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _fraisController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Frais d\'adhésion (FCFA)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
enabled: !_loading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _loading ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Créer'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/// Dialog pour enregistrer un paiement sur une adhésion
|
||||
library paiement_adhesion_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
|
||||
class PaiementAdhesionDialog extends StatefulWidget {
|
||||
final String adhesionId;
|
||||
final double montantRestant;
|
||||
final VoidCallback onPaid;
|
||||
|
||||
const PaiementAdhesionDialog({
|
||||
super.key,
|
||||
required this.adhesionId,
|
||||
required this.montantRestant,
|
||||
required this.onPaid,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PaiementAdhesionDialog> createState() => _PaiementAdhesionDialogState();
|
||||
}
|
||||
|
||||
class _PaiementAdhesionDialogState extends State<PaiementAdhesionDialog> {
|
||||
final _montantController = TextEditingController();
|
||||
final _refController = TextEditingController();
|
||||
String? _methode;
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_montantController.text = widget.montantRestant.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_montantController.dispose();
|
||||
_refController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final montant = double.tryParse(_montantController.text.replaceAll(',', '.'));
|
||||
if (montant == null || montant <= 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Montant invalide')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (montant > widget.montantRestant) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Le montant ne peut pas dépasser le restant dû')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _loading = true);
|
||||
context.read<AdhesionsBloc>().add(
|
||||
EnregistrerPaiementAdhesion(
|
||||
widget.adhesionId,
|
||||
montantPaye: montant,
|
||||
methodePaiement: _methode,
|
||||
referencePaiement: _refController.text.trim().isEmpty
|
||||
? null
|
||||
: _refController.text.trim(),
|
||||
),
|
||||
);
|
||||
widget.onPaid();
|
||||
if (mounted) {
|
||||
setState(() => _loading = false);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Enregistrer un paiement'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Restant dû : ${widget.montantRestant.toStringAsFixed(0)} FCFA'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _montantController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Montant payé (FCFA)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
enabled: !_loading,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _methode,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Méthode de paiement',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'ESPECES', child: Text('Espèces')),
|
||||
DropdownMenuItem(value: 'VIREMENT', child: Text('Virement')),
|
||||
DropdownMenuItem(value: 'WAVE_MONEY', child: Text('Wave Money')),
|
||||
DropdownMenuItem(value: 'ORANGE_MONEY', child: Text('Orange Money')),
|
||||
DropdownMenuItem(value: 'CHEQUE', child: Text('Chèque')),
|
||||
],
|
||||
onChanged: _loading ? null : (v) => setState(() => _methode = v),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _refController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Référence (optionnel)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
enabled: !_loading,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _loading ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Enregistrer'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/// Dialog pour rejeter une adhésion (saisie du motif)
|
||||
library rejet_adhesion_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
|
||||
class RejetAdhesionDialog extends StatefulWidget {
|
||||
final String adhesionId;
|
||||
final VoidCallback onRejected;
|
||||
|
||||
const RejetAdhesionDialog({
|
||||
super.key,
|
||||
required this.adhesionId,
|
||||
required this.onRejected,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RejetAdhesionDialog> createState() => _RejetAdhesionDialogState();
|
||||
}
|
||||
|
||||
class _RejetAdhesionDialogState extends State<RejetAdhesionDialog> {
|
||||
final _controller = TextEditingController();
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final motif = _controller.text.trim();
|
||||
if (motif.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Veuillez saisir un motif de rejet')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _loading = true);
|
||||
context.read<AdhesionsBloc>().add(RejeterAdhesion(widget.adhesionId, motif));
|
||||
widget.onRejected();
|
||||
if (mounted) {
|
||||
setState(() => _loading = false);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Rejeter la demande'),
|
||||
content: TextField(
|
||||
controller: _controller,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Motif du rejet',
|
||||
hintText: 'Saisir le motif...',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
maxLines: 3,
|
||||
enabled: !_loading,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _loading ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _loading ? null : _submit,
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red),
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Rejeter'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user