From 6bf43369c46535fb8dda74372d7a9c62cd0161c2 Mon Sep 17 00:00:00 2001 From: orangdeso Date: Tue, 6 May 2025 15:30:36 +0700 Subject: [PATCH] Feat: fix bug in features history transaction porter --- .dart_tool/package_config.json | 2 +- .../transaction_porter_repository_impl.dart | 2 +- .../transaction_porter_controller.dart | 53 ----------- .../pages/detail_history_porter_screen.dart | 91 +++++++++++++++++-- .../screens/routes/app_rountes.dart | 6 +- 5 files changed, 89 insertions(+), 65 deletions(-) diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 23bd76d..7a81036 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -638,7 +638,7 @@ "languageVersion": "3.4" } ], - "generated": "2025-04-30T16:03:15.794012Z", + "generated": "2025-05-05T05:14:47.271498Z", "generator": "pub", "generatorVersion": "3.5.0", "flutterRoot": "file:///D:/Flutter/flutter_sdk/flutter_3.24.0", diff --git a/lib/data/repositories/transaction_porter_repository_impl.dart b/lib/data/repositories/transaction_porter_repository_impl.dart index 8e835cf..07bf1d2 100644 --- a/lib/data/repositories/transaction_porter_repository_impl.dart +++ b/lib/data/repositories/transaction_porter_repository_impl.dart @@ -670,7 +670,7 @@ class TransactionPorterRepositoryImpl implements TransactionPorterRepository { 'isAvailable': false, 'idTransaction': transactionId, 'idUser': txData['idPassenger'] ?? '', - 'lastAssigned': now, + 'onlineAt': now, }); // 6. Update transaksi utama dengan format ReassignmentInfo diff --git a/lib/presentation/controllers/transaction_porter_controller.dart b/lib/presentation/controllers/transaction_porter_controller.dart index 96a04d2..ecb52c2 100644 --- a/lib/presentation/controllers/transaction_porter_controller.dart +++ b/lib/presentation/controllers/transaction_porter_controller.dart @@ -5,7 +5,6 @@ import 'package:e_porter/_core/service/preferences_service.dart'; import 'package:e_porter/_core/utils/snackbar/snackbar_helper.dart'; import 'package:e_porter/domain/models/porter_queue_model.dart'; import 'package:e_porter/presentation/screens/boarding_pass/provider/porter_service_provider.dart'; -import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../domain/models/transaction_porter_model.dart'; import '../../domain/usecases/transaction_porter_usecase.dart'; @@ -30,8 +29,6 @@ class TransactionPorterController extends GetxController { final RxBool isRejecting = false.obs; final RxBool needsRefresh = false.obs; - final TextEditingController rejectionReasonController = TextEditingController(); - StreamSubscription>? _subscription; StreamSubscription? _porterSubscription; StreamSubscription>? _rejectedSubscription; @@ -524,18 +521,15 @@ class TransactionPorterController extends GetxController { void showRejectDialog() { rejectionReason.value = ''; - rejectionReasonController.clear(); isRejectionDialogVisible.value = true; } void hideRejectDialog() { isRejectionDialogVisible.value = false; - rejectionReasonController.clear(); } @override void onClose() { - rejectionReasonController.dispose(); _porterSubscription?.cancel(); _subscription?.cancel(); _rejectedSubscription?.cancel(); @@ -545,51 +539,4 @@ class TransactionPorterController extends GetxController { _transactionWatchers.clear(); super.onClose(); } - - void showRejectionDialog(String transactionId, BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Tolak Permintaan Porter'), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('Masukkan alasan penolakan:'), - const SizedBox(height: 10), - TextField( - controller: rejectionReasonController, - decoration: const InputDecoration( - hintText: 'Contoh: Sedang melayani penumpang lain', - border: OutlineInputBorder(), - ), - maxLines: 3, - ), - ], - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - rejectionReasonController.clear(); - }, - child: const Text('Batal'), - ), - TextButton( - onPressed: () { - final reason = rejectionReasonController.text.trim(); - Navigator.of(context).pop(); - rejectTransaction( - transactionId: transactionId, - reason: reason, - ); - }, - child: const Text('Tolak'), - style: TextButton.styleFrom(foregroundColor: Colors.red), - ), - ], - ); - }, - ); - } } diff --git a/lib/presentation/screens/boarding_pass/pages/detail_history_porter_screen.dart b/lib/presentation/screens/boarding_pass/pages/detail_history_porter_screen.dart index 9f7c1ab..dcdac4c 100644 --- a/lib/presentation/screens/boarding_pass/pages/detail_history_porter_screen.dart +++ b/lib/presentation/screens/boarding_pass/pages/detail_history_porter_screen.dart @@ -7,10 +7,13 @@ import 'package:e_porter/_core/component/button/button_fill.dart'; import 'package:e_porter/_core/component/card/custome_shadow_cotainner.dart'; import 'package:e_porter/_core/constants/colors.dart'; import 'package:e_porter/_core/constants/typography.dart'; +import 'package:e_porter/_core/utils/snackbar/snackbar_helper.dart'; import 'package:e_porter/domain/models/transaction_model.dart'; import 'package:e_porter/domain/models/transaction_porter_model.dart'; import 'package:e_porter/presentation/controllers/history_controller.dart'; +import 'package:e_porter/presentation/controllers/navigation_controller.dart'; import 'package:e_porter/presentation/controllers/transaction_porter_controller.dart'; +import 'package:e_porter/presentation/screens/navigation/main_navigation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -27,6 +30,7 @@ class DetailHistoryPorterScreen extends StatefulWidget { class _DetailHistoryPorterScreenState extends State { final TransactionPorterController _porterController = Get.find(); final HistoryController _historyController = Get.find(); + final _reasonController = TextEditingController(); PorterTransactionModel? porterTransaction; @@ -42,12 +46,16 @@ class _DetailHistoryPorterScreenState extends State { final args = Get.arguments as Map; porterTransactionId = args['transactionPorterId']; - WidgetsBinding.instance.addPostFrameCallback((_) { - _fetchTransactioPorterById(); - _fetchTransactionData(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + await _fetchTransactioPorterById(); + await _fetchTransactionData(); }); + } - log('[Detail History Porter] ID Transaction Porter : $porterTransactionId'); + @override + void dispose() { + _reasonController.dispose(); + super.dispose(); } Future _fetchTransactioPorterById() async { @@ -91,10 +99,7 @@ class _DetailHistoryPorterScreenState extends State { if (porterTransaction.ticketId.isNotEmpty && porterTransaction.transactionId.isNotEmpty) { await _historyController.getTransactionFromFirestore( porterTransaction.ticketId, porterTransaction.transactionId); - - log('[Detail History Porter] Berhasil mengambil ticket transaction'); } else { - log('[Detail History Porter] ticketId atau transactionId kosong'); _historyController.selectedTransaction.value = null; } } @@ -105,6 +110,50 @@ class _DetailHistoryPorterScreenState extends State { } } + void _showRejectionDialog() { + showDialog( + context: context, + builder: (_) => AlertDialog( + title: Text('Tolak Permintaan Porter'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text('Masukkan alasan penolakan:'), + SizedBox(height: 10), + TextField( + controller: _reasonController, + decoration: InputDecoration( + hintText: 'Sedang melayani penumpang lain', + border: OutlineInputBorder(), + ), + maxLines: 3, + ), + ], + ), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + _reasonController.clear(); + }, + child: Text('Batal'), + ), + TextButton( + onPressed: () { + final reason = _reasonController.text.trim(); + Navigator.pop(context); + _porterController.rejectTransaction( + transactionId: porterTransactionId, + reason: reason, + ); + }, + child: Text('Tolak', style: TextStyle(color: Colors.red)), + ), + ], + ), + ); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -167,7 +216,31 @@ class _DetailHistoryPorterScreenState extends State { textColor: Colors.white, backgroundColor: PrimaryColors.primary700, onTap: () { - _porterController.forceReassignTransaction(porterTransactionId); + Get.dialog( + const Center(child: CircularProgressIndicator()), + barrierDismissible: false, + ); + + Get.delete(); + Get.put(NavigationController()); + Get.offAll( + () => MainNavigation(initialTabIndex: 1), + arguments: 'porter', + ); + + _porterController.forceReassignTransaction(porterTransactionId).then((_) { + if (Get.isDialogOpen ?? false) Get.back(); + SnackbarHelper.showSuccess( + 'Berhasil', + 'Transaksi berhasil dialihkan ke porter lain', + ); + }).catchError((e) { + if (Get.isDialogOpen ?? false) Get.back(); + SnackbarHelper.showError( + 'Gagal', + 'Transaksi gagal dialihkan: $e', + ); + }); }, ), ); @@ -184,7 +257,7 @@ class _DetailHistoryPorterScreenState extends State { textColor: Colors.white, backgroundColor: RedColors.red500, onTap: () { - _porterController.showRejectionDialog(porterTransactionId, context); + _showRejectionDialog(); }, ), ), diff --git a/lib/presentation/screens/routes/app_rountes.dart b/lib/presentation/screens/routes/app_rountes.dart index 6d7a3e9..50d9eb5 100644 --- a/lib/presentation/screens/routes/app_rountes.dart +++ b/lib/presentation/screens/routes/app_rountes.dart @@ -175,7 +175,11 @@ class AppRoutes { GetPage( name: Routes.DETAILHISTORYPORTER, page: () => DetailHistoryPorterScreen(), - binding: TransactionPorterBinding() + bindings: [ + TransactionPorterBinding(), + TransactionBinding(), + HistoryBinding(), + ], ), GetPage( name: Routes.ADDPASSENGER,