Refactor clock-in feature: Introduce validation pipeline and interaction strategies
- Added a validation pipeline for clock-in actions, including geofence, time window, and override notes validators. - Created a context class for passing validation data and results. - Implemented check-in interaction strategies for swipe and NFC methods, encapsulating their UI and behavior. - Removed redundant utility functions and centralized time formatting in a new utility file. - Enhanced the notification service to handle clock-in and clock-out notifications separately. - Updated the ClockInBloc to utilize the new validation and notification services. - Cleaned up the ClockInActionSection widget to use the new interaction strategies and removed unnecessary listeners.
This commit is contained in:
@@ -6,6 +6,7 @@ export 'src/domain/arguments/usecase_argument.dart';
|
||||
export 'src/domain/usecases/usecase.dart';
|
||||
export 'src/utils/date_time_utils.dart';
|
||||
export 'src/utils/geo_utils.dart';
|
||||
export 'src/utils/time_utils.dart';
|
||||
export 'src/presentation/widgets/web_mobile_frame.dart';
|
||||
export 'src/presentation/mixins/bloc_error_handler.dart';
|
||||
export 'src/presentation/observers/core_bloc_observer.dart';
|
||||
|
||||
30
apps/mobile/packages/core/lib/src/utils/time_utils.dart
Normal file
30
apps/mobile/packages/core/lib/src/utils/time_utils.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Formats a time string (ISO 8601 or HH:mm) into 12-hour format
|
||||
/// (e.g. "9:00 AM").
|
||||
///
|
||||
/// Returns the original string unchanged if parsing fails.
|
||||
String formatTime(String timeStr) {
|
||||
if (timeStr.isEmpty) return '';
|
||||
try {
|
||||
final DateTime dt = DateTime.parse(timeStr);
|
||||
return DateFormat('h:mm a').format(dt);
|
||||
} catch (_) {
|
||||
try {
|
||||
final List<String> parts = timeStr.split(':');
|
||||
if (parts.length >= 2) {
|
||||
final DateTime dt = DateTime(
|
||||
2022,
|
||||
1,
|
||||
1,
|
||||
int.parse(parts[0]),
|
||||
int.parse(parts[1]),
|
||||
);
|
||||
return DateFormat('h:mm a').format(dt);
|
||||
}
|
||||
return timeStr;
|
||||
} catch (_) {
|
||||
return timeStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user