feat: Enhance trip end dialog to check trip creator and prompt accordingly
This commit is contained in:
@@ -269,18 +269,45 @@ class _HomeContentState extends State<HomeContent>
|
|||||||
|
|
||||||
/// Vérifie les voyages terminés et affiche le dialog de suppression si besoin.
|
/// Vérifie les voyages terminés et affiche le dialog de suppression si besoin.
|
||||||
Future<void> _checkFinishedTrips(List<Trip> trips) async {
|
Future<void> _checkFinishedTrips(List<Trip> trips) async {
|
||||||
|
final userState = context.read<UserBloc>().state;
|
||||||
|
if (userState is! UserLoaded) return;
|
||||||
|
final currentUserId = userState.user.id;
|
||||||
|
|
||||||
final finished = await _tripEndService.getFinishedTripsNotYetPrompted(trips);
|
final finished = await _tripEndService.getFinishedTripsNotYetPrompted(trips);
|
||||||
for (final trip in finished) {
|
for (final trip in finished) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await _showTripEndDialog(trip);
|
await _showTripEndDialog(trip, currentUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Affiche le dialog demandant si l'utilisateur veut supprimer le voyage terminé.
|
/// Affiche le dialog demandant si l'utilisateur veut supprimer le voyage terminé.
|
||||||
Future<void> _showTripEndDialog(Trip trip) async {
|
Future<void> _showTripEndDialog(Trip trip, String currentUserId) async {
|
||||||
final tripId = trip.id!;
|
final tripId = trip.id!;
|
||||||
await _tripEndService.markTripAsPrompted(tripId);
|
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<void>(
|
||||||
|
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);
|
final settled = await _tripEndService.areAccountsSettled(tripId);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user