From ed854cb95893f10bf1089b0e63edaba14501f919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Salazar?= <73718835+joshrs23@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:00:55 -0500 Subject: [PATCH] solving problem with apply button --- .../core/lib/src/routing/staff/navigator.dart | 9 ++++++- .../blocs/shifts/shifts_bloc.dart | 10 ++++++-- .../blocs/shifts/shifts_event.dart | 8 ++++++- .../pages/shift_details_page.dart | 9 +++++-- .../src/presentation/pages/shifts_page.dart | 24 +++++++++++++++++-- .../shifts/lib/src/staff_shifts_module.dart | 1 + 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/apps/mobile/packages/core/lib/src/routing/staff/navigator.dart b/apps/mobile/packages/core/lib/src/routing/staff/navigator.dart index 3ba4a8ea..0f624872 100644 --- a/apps/mobile/packages/core/lib/src/routing/staff/navigator.dart +++ b/apps/mobile/packages/core/lib/src/routing/staff/navigator.dart @@ -98,7 +98,11 @@ extension StaffNavigator on IModularNavigator { /// Parameters: /// * [selectedDate] - Optional date to pre-select in the shifts view /// * [initialTab] - Optional initial tab (via query parameter) - void toShifts({DateTime? selectedDate, String? initialTab}) { + void toShifts({ + DateTime? selectedDate, + String? initialTab, + bool? refreshAvailable, + }) { final Map args = {}; if (selectedDate != null) { args['selectedDate'] = selectedDate; @@ -106,6 +110,9 @@ extension StaffNavigator on IModularNavigator { if (initialTab != null) { args['initialTab'] = initialTab; } + if (refreshAvailable == true) { + args['refreshAvailable'] = true; + } navigate( StaffPaths.shifts, arguments: args.isEmpty ? null : args, diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_bloc.dart b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_bloc.dart index 6a8c1c43..e6e0fe97 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_bloc.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_bloc.dart @@ -108,9 +108,15 @@ class ShiftsBloc extends Bloc ) async { final currentState = state; if (currentState is! ShiftsLoaded) return; - if (currentState.availableLoading || currentState.availableLoaded) return; + if (!event.force && + (currentState.availableLoading || currentState.availableLoaded)) { + return; + } - emit(currentState.copyWith(availableLoading: true)); + emit(currentState.copyWith( + availableLoading: true, + availableLoaded: false, + )); await handleError( emit: emit, action: () async { diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_event.dart b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_event.dart index d25866e0..55ea9fd1 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_event.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/blocs/shifts/shifts_event.dart @@ -12,7 +12,13 @@ class LoadShiftsEvent extends ShiftsEvent {} class LoadHistoryShiftsEvent extends ShiftsEvent {} -class LoadAvailableShiftsEvent extends ShiftsEvent {} +class LoadAvailableShiftsEvent extends ShiftsEvent { + final bool force; + const LoadAvailableShiftsEvent({this.force = false}); + + @override + List get props => [force]; +} class LoadFindFirstEvent extends ShiftsEvent {} diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shift_details_page.dart b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shift_details_page.dart index e4563de1..b2a17a60 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shift_details_page.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shift_details_page.dart @@ -93,7 +93,11 @@ class _ShiftDetailsPageState extends State { message: state.message, type: UiSnackbarType.success, ); - Modular.to.toShifts(selectedDate: state.shiftDate); + Modular.to.toShifts( + selectedDate: state.shiftDate, + initialTab: 'find', + refreshAvailable: true, + ); } else if (state is ShiftDetailsError) { if (_isApplying) { UiSnackbar.show( @@ -112,7 +116,8 @@ class _ShiftDetailsPageState extends State { ); } - Shift displayShift = widget.shift; + final Shift displayShift = + state is ShiftDetailsLoaded ? state.shift : widget.shift; final i18n = Translations.of(context).staff_shifts.shift_details; final duration = _calculateDuration(displayShift); diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shifts_page.dart b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shifts_page.dart index 32ffc356..13776407 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shifts_page.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/presentation/pages/shifts_page.dart @@ -12,7 +12,13 @@ import '../widgets/tabs/history_shifts_tab.dart'; class ShiftsPage extends StatefulWidget { final String? initialTab; final DateTime? selectedDate; - const ShiftsPage({super.key, this.initialTab, this.selectedDate}); + final bool refreshAvailable; + const ShiftsPage({ + super.key, + this.initialTab, + this.selectedDate, + this.refreshAvailable = false, + }); @override State createState() => _ShiftsPageState(); @@ -22,6 +28,8 @@ class _ShiftsPageState extends State { late String _activeTab; DateTime? _selectedDate; bool _prioritizeFind = false; + bool _refreshAvailable = false; + bool _pendingAvailableRefresh = false; final ShiftsBloc _bloc = Modular.get(); @override @@ -30,6 +38,8 @@ class _ShiftsPageState extends State { _activeTab = widget.initialTab ?? 'myshifts'; _selectedDate = widget.selectedDate; _prioritizeFind = widget.initialTab == 'find'; + _refreshAvailable = widget.refreshAvailable; + _pendingAvailableRefresh = widget.refreshAvailable; if (_prioritizeFind) { _bloc.add(LoadFindFirstEvent()); } else { @@ -40,7 +50,9 @@ class _ShiftsPageState extends State { } if (_activeTab == 'find') { if (!_prioritizeFind) { - _bloc.add(LoadAvailableShiftsEvent()); + _bloc.add( + LoadAvailableShiftsEvent(force: _refreshAvailable), + ); } } } @@ -59,6 +71,10 @@ class _ShiftsPageState extends State { _selectedDate = widget.selectedDate; }); } + if (widget.refreshAvailable) { + _refreshAvailable = true; + _pendingAvailableRefresh = true; + } } @override @@ -77,6 +93,10 @@ class _ShiftsPageState extends State { } }, builder: (context, state) { + if (_pendingAvailableRefresh && state is ShiftsLoaded) { + _pendingAvailableRefresh = false; + _bloc.add(const LoadAvailableShiftsEvent(force: true)); + } final bool baseLoaded = state is ShiftsLoaded; final List myShifts = (state is ShiftsLoaded) ? state.myShifts diff --git a/apps/mobile/packages/features/staff/shifts/lib/src/staff_shifts_module.dart b/apps/mobile/packages/features/staff/shifts/lib/src/staff_shifts_module.dart index 02bade2c..16518dcb 100644 --- a/apps/mobile/packages/features/staff/shifts/lib/src/staff_shifts_module.dart +++ b/apps/mobile/packages/features/staff/shifts/lib/src/staff_shifts_module.dart @@ -46,6 +46,7 @@ class StaffShiftsModule extends Module { return ShiftsPage( initialTab: queryParams['tab'] ?? args?['initialTab'], selectedDate: args?['selectedDate'], + refreshAvailable: args?['refreshAvailable'] == true, ); }, );