From 7ed90db7a86d322289bdb7fb7369ac4468ed03a2 Mon Sep 17 00:00:00 2001 From: Van Leemput Dayron Date: Fri, 20 Mar 2026 10:37:04 +0100 Subject: [PATCH] feat: Enhance trip end dialog to check trip creator and prompt accordingly --- lib/components/home/home_content.dart | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/components/home/home_content.dart b/lib/components/home/home_content.dart index 30bf01c..f26135f 100644 --- a/lib/components/home/home_content.dart +++ b/lib/components/home/home_content.dart @@ -269,18 +269,45 @@ class _HomeContentState extends State /// Vérifie les voyages terminés et affiche le dialog de suppression si besoin. Future _checkFinishedTrips(List trips) async { + final userState = context.read().state; + if (userState is! UserLoaded) return; + final currentUserId = userState.user.id; + final finished = await _tripEndService.getFinishedTripsNotYetPrompted(trips); for (final trip in finished) { if (!mounted) return; - await _showTripEndDialog(trip); + await _showTripEndDialog(trip, currentUserId); } } /// Affiche le dialog demandant si l'utilisateur veut supprimer le voyage terminé. - Future _showTripEndDialog(Trip trip) async { + Future _showTripEndDialog(Trip trip, String currentUserId) async { final tripId = trip.id!; await _tripEndService.markTripAsPrompted(tripId); + final isCreator = trip.createdBy == currentUserId; + + // Si l'utilisateur n'est pas le créateur, afficher uniquement une info + if (!isCreator) { + if (!mounted) return; + await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: const Text('Voyage terminé'), + content: Text( + 'Le voyage "${trip.title}" est terminé. Seul le créateur du voyage peut le supprimer.', + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(ctx), + child: const Text('OK'), + ), + ], + ), + ); + return; + } + final settled = await _tripEndService.areAccountsSettled(tripId); if (!mounted) return;