diff --git a/lib/helpers/services/notification_action_handler.dart b/lib/helpers/services/notification_action_handler.dart index a8073f3..776786e 100644 --- a/lib/helpers/services/notification_action_handler.dart +++ b/lib/helpers/services/notification_action_handler.dart @@ -209,10 +209,11 @@ class NotificationActionHandler { /// ---------------------- DOCUMENT HANDLER ---------------------- static void _handleDocumentModified(Map data) { - late String entityTypeId; - late String entityId; + String entityTypeId; + String entityId; String? documentId = data['DocumentId']; + // Determine entity type and ID if (data['Keyword'] == 'Employee_Document_Modified') { entityTypeId = Permissions.employeeEntity; entityId = data['EmployeeId'] ?? ''; @@ -229,30 +230,43 @@ class NotificationActionHandler { return; } - _safeControllerUpdate( - onFound: (controller) async { - await controller.fetchDocuments( - entityTypeId: entityTypeId, - entityId: entityId, - reset: true, - ); - }, - notFoundMessage: 'âš ī¸ DocumentController not found, cannot refresh list.', - successMessage: '✅ DocumentController refreshed from notification.', - ); + _logger.i( + "🔔 Document notification received: keyword=${data['Keyword']}, entityTypeId=$entityTypeId, entityId=$entityId, documentId=$documentId"); - if (documentId != null) { + // Refresh Document List + if (Get.isRegistered()) { + _safeControllerUpdate( + onFound: (controller) async { + await controller.fetchDocuments( + entityTypeId: entityTypeId, + entityId: entityId, + reset: true, + ); + }, + notFoundMessage: + 'âš ī¸ DocumentController not found, cannot refresh list.', + successMessage: '✅ DocumentController refreshed from notification.', + ); + } else { + _logger.w('âš ī¸ DocumentController not registered, skipping list refresh.'); + } + + // Refresh Document Details (if open) + if (documentId != null && Get.isRegistered()) { _safeControllerUpdate( onFound: (controller) async { - if (controller.documentDetails.value?.data?.id == documentId) { - await controller.fetchDocumentDetails(documentId); - _logger.i( - "✅ DocumentDetailsController refreshed for Document $documentId"); - } + // Refresh details regardless of current document + await controller.fetchDocumentDetails(documentId); + _logger.i( + "✅ DocumentDetailsController refreshed for Document $documentId"); }, - notFoundMessage: 'â„šī¸ DocumentDetailsController not active, skipping.', + notFoundMessage: + 'â„šī¸ DocumentDetailsController not active, skipping details refresh.', successMessage: '✅ DocumentDetailsController checked for refresh.', ); + } else if (documentId != null) { + _logger.w( + 'âš ī¸ DocumentDetailsController not registered, cannot refresh document details.'); } } @@ -313,7 +327,8 @@ class NotificationActionHandler { break; case 'task_updated': await controller.fetchDashboardTasks( - projectId: controller.projectController.selectedProjectId.value); + projectId: + controller.projectController.selectedProjectId.value); break; case 'project_progress_update': await controller.fetchProjectProgress(); diff --git a/lib/view/document/document_details_page.dart b/lib/view/document/document_details_page.dart index b931844..d84481a 100644 --- a/lib/view/document/document_details_page.dart +++ b/lib/view/document/document_details_page.dart @@ -25,7 +25,8 @@ class DocumentDetailsPage extends StatefulWidget { class _DocumentDetailsPageState extends State { final DocumentDetailsController controller = - Get.put(DocumentDetailsController()); + Get.find(); + final PermissionController permissionController = Get.find(); @override diff --git a/lib/view/document/user_document_screen.dart b/lib/view/document/user_document_screen.dart index dadada1..caafcf3 100644 --- a/lib/view/document/user_document_screen.dart +++ b/lib/view/document/user_document_screen.dart @@ -17,9 +17,9 @@ import 'package:marco/helpers/widgets/custom_app_bar.dart'; import 'package:marco/helpers/widgets/my_confirmation_dialog.dart'; import 'package:marco/helpers/widgets/my_snackbar.dart'; import 'package:marco/controller/permission_controller.dart'; +import 'package:marco/controller/document/document_details_controller.dart'; import 'dart:convert'; - class UserDocumentsPage extends StatefulWidget { final String? entityId; final bool isEmployee; @@ -38,7 +38,8 @@ class _UserDocumentsPageState extends State { final DocumentController docController = Get.put(DocumentController()); final PermissionController permissionController = Get.find(); - + final DocumentDetailsController controller = + Get.put(DocumentDetailsController()); String get entityTypeId => widget.isEmployee ? Permissions.employeeEntity : Permissions.projectEntity; @@ -586,8 +587,7 @@ class _UserDocumentsPageState extends State { isScrollControlled: true, backgroundColor: Colors.transparent, builder: (_) => DocumentUploadBottomSheet( - isEmployee: - widget.isEmployee, + isEmployee: widget.isEmployee, onSubmit: (data) async { final success = await uploadController.uploadDocument( name: data["name"],