marco.pms.mobileapp/lib/helpers/services/notification_action_handler.dart

53 lines
1.7 KiB
Dart

import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
/// Handles incoming FCM notification actions and updates UI/controllers.
class NotificationActionHandler {
static final Logger _logger = Logger();
/// Main entry point — call this for any notification `data` map.
static void handle(Map<String, dynamic> data) {
_logger.i('📲 Handling notification action: $data');
if (data.isEmpty) {
_logger.w('⚠️ Empty notification data received.');
return;
}
final type = data['type'];
final action = data['Action'];
final keyword = data['Keyword'];
if (type != null) {
switch (type) {
case 'expense_updated':
break;
case 'attendance_updated':
_handleAttendanceUpdated(data);
break;
default:
_logger.w('⚠️ Unknown notification type: $type');
}
} else if (keyword == 'Attendance' && action == 'CHECK_IN' || action == 'CHECK_OUT' || action == 'REQUEST_REGULARIZE ' || action == 'REQUEST_DELETE '|| action == 'REGULARIZE ' || action == 'REGULARIZE_REJECT ') {
// Matches your current logs
_handleAttendanceUpdated(data);
} else {
_logger.w('⚠️ Unhandled notification: $data');
}
}
static void _handleAttendanceUpdated(Map<String, dynamic> data) {
try {
final controller = Get.find<AttendanceController>();
controller.refreshDataFromNotification(
projectId: data['ProjectId'],
);
_logger.i('✅ AttendanceController refreshed from notification.');
} catch (e) {
_logger.w('⚠️ AttendanceController not found, cannot update.');
}
}
}