Reapply "Merge pull request #373 from Oloodi/368-sub-task-provision-and-copy-validation-database-instance"
This reverts commit eb149f680b.
This commit is contained in:
@@ -95,10 +95,10 @@ class ClientHubsPage extends StatelessWidget {
|
||||
).add(
|
||||
ClientHubsIdentifyDialogToggled(hub: hub),
|
||||
),
|
||||
onDeletePressed: () =>
|
||||
BlocProvider.of<ClientHubsBloc>(
|
||||
context,
|
||||
).add(ClientHubsDeleteRequested(hub.id)),
|
||||
onDeletePressed: () => _confirmDeleteHub(
|
||||
context,
|
||||
hub,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -221,4 +221,51 @@ class ClientHubsPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _confirmDeleteHub(BuildContext context, Hub hub) async {
|
||||
final String hubName = hub.name.isEmpty ? 'this hub' : hub.name;
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Hub Deletion'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('Are you sure you want to delete "$hubName"?'),
|
||||
const SizedBox(height: UiConstants.space2),
|
||||
const Text('This action cannot be undone.'),
|
||||
const SizedBox(height: UiConstants.space2),
|
||||
Text(
|
||||
'Note that if there are any shifts/orders assigned to this hub we shouldn\'t be able to delete the hub.',
|
||||
style: UiTypography.footnote1r.copyWith(
|
||||
color: UiColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Modular.to.pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
BlocProvider.of<ClientHubsBloc>(
|
||||
context,
|
||||
).add(ClientHubsDeleteRequested(hub.id));
|
||||
Modular.to.pop();
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: UiColors.destructive,
|
||||
),
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class SettingsActions extends StatelessWidget {
|
||||
// Cancel button
|
||||
UiButton.secondary(
|
||||
text: t.common.cancel,
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
onPressed: () => Modular.to.pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -31,9 +31,11 @@ extension HomeNavigator on IModularNavigator {
|
||||
/// Optionally provide a [tab] query param (e.g. `find`).
|
||||
void pushShifts({String? tab}) {
|
||||
if (tab == null) {
|
||||
pushNamed('/worker-main/shifts');
|
||||
navigate('/worker-main/shifts');
|
||||
} else {
|
||||
pushNamed('/worker-main/shifts?tab=$tab');
|
||||
navigate('/worker-main/shifts', arguments: <String, dynamic>{
|
||||
'initialTab': tab,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,8 +132,7 @@ class WorkerHomePage extends StatelessWidget {
|
||||
EmptyStateWidget(
|
||||
message: emptyI18n.no_shifts_today,
|
||||
actionLink: emptyI18n.find_shifts_cta,
|
||||
onAction: () =>
|
||||
Modular.to.pushShifts(tab: 'find'),
|
||||
onAction: () => Modular.to.pushShifts(tab: 'find'),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
|
||||
@@ -31,6 +31,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
on<LoadShiftsEvent>(_onLoadShifts);
|
||||
on<LoadHistoryShiftsEvent>(_onLoadHistoryShifts);
|
||||
on<LoadAvailableShiftsEvent>(_onLoadAvailableShifts);
|
||||
on<LoadFindFirstEvent>(_onLoadFindFirst);
|
||||
on<LoadShiftsForRangeEvent>(_onLoadShiftsForRange);
|
||||
on<FilterAvailableShiftsEvent>(_onFilterAvailableShifts);
|
||||
}
|
||||
@@ -62,6 +63,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
availableLoaded: false,
|
||||
historyLoading: false,
|
||||
historyLoaded: false,
|
||||
myShiftsLoaded: true,
|
||||
searchQuery: '',
|
||||
jobType: 'all',
|
||||
));
|
||||
@@ -82,6 +84,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
try {
|
||||
final historyResult = await getHistoryShifts();
|
||||
emit(currentState.copyWith(
|
||||
myShiftsLoaded: true,
|
||||
historyShifts: historyResult,
|
||||
historyLoading: false,
|
||||
historyLoaded: true,
|
||||
@@ -113,6 +116,67 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onLoadFindFirst(
|
||||
LoadFindFirstEvent event,
|
||||
Emitter<ShiftsState> emit,
|
||||
) async {
|
||||
if (state is! ShiftsLoaded) {
|
||||
emit(const ShiftsLoaded(
|
||||
myShifts: [],
|
||||
pendingShifts: [],
|
||||
cancelledShifts: [],
|
||||
availableShifts: [],
|
||||
historyShifts: [],
|
||||
availableLoading: false,
|
||||
availableLoaded: false,
|
||||
historyLoading: false,
|
||||
historyLoaded: false,
|
||||
myShiftsLoaded: false,
|
||||
searchQuery: '',
|
||||
jobType: 'all',
|
||||
));
|
||||
}
|
||||
|
||||
final currentState =
|
||||
state is ShiftsLoaded ? state as ShiftsLoaded : null;
|
||||
if (currentState != null && currentState.availableLoaded) return;
|
||||
|
||||
if (currentState != null) {
|
||||
emit(currentState.copyWith(availableLoading: true));
|
||||
}
|
||||
|
||||
try {
|
||||
final availableResult =
|
||||
await getAvailableShifts(const GetAvailableShiftsArguments());
|
||||
final loadedState = state is ShiftsLoaded
|
||||
? state as ShiftsLoaded
|
||||
: const ShiftsLoaded(
|
||||
myShifts: [],
|
||||
pendingShifts: [],
|
||||
cancelledShifts: [],
|
||||
availableShifts: [],
|
||||
historyShifts: [],
|
||||
availableLoading: true,
|
||||
availableLoaded: false,
|
||||
historyLoading: false,
|
||||
historyLoaded: false,
|
||||
myShiftsLoaded: false,
|
||||
searchQuery: '',
|
||||
jobType: 'all',
|
||||
);
|
||||
emit(loadedState.copyWith(
|
||||
availableShifts: _filterPastShifts(availableResult),
|
||||
availableLoading: false,
|
||||
availableLoaded: true,
|
||||
));
|
||||
} catch (_) {
|
||||
if (state is ShiftsLoaded) {
|
||||
final current = state as ShiftsLoaded;
|
||||
emit(current.copyWith(availableLoading: false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onLoadShiftsForRange(
|
||||
LoadShiftsForRangeEvent event,
|
||||
Emitter<ShiftsState> emit,
|
||||
@@ -124,7 +188,10 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
|
||||
if (state is ShiftsLoaded) {
|
||||
final currentState = state as ShiftsLoaded;
|
||||
emit(currentState.copyWith(myShifts: myShiftsResult));
|
||||
emit(currentState.copyWith(
|
||||
myShifts: myShiftsResult,
|
||||
myShiftsLoaded: true,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,6 +205,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
||||
availableLoaded: false,
|
||||
historyLoading: false,
|
||||
historyLoaded: false,
|
||||
myShiftsLoaded: true,
|
||||
searchQuery: '',
|
||||
jobType: 'all',
|
||||
));
|
||||
|
||||
@@ -14,6 +14,8 @@ class LoadHistoryShiftsEvent extends ShiftsEvent {}
|
||||
|
||||
class LoadAvailableShiftsEvent extends ShiftsEvent {}
|
||||
|
||||
class LoadFindFirstEvent extends ShiftsEvent {}
|
||||
|
||||
class LoadShiftsForRangeEvent extends ShiftsEvent {
|
||||
final DateTime start;
|
||||
final DateTime end;
|
||||
|
||||
@@ -22,6 +22,7 @@ class ShiftsLoaded extends ShiftsState {
|
||||
final bool availableLoaded;
|
||||
final bool historyLoading;
|
||||
final bool historyLoaded;
|
||||
final bool myShiftsLoaded;
|
||||
final String searchQuery;
|
||||
final String jobType;
|
||||
|
||||
@@ -35,6 +36,7 @@ class ShiftsLoaded extends ShiftsState {
|
||||
required this.availableLoaded,
|
||||
required this.historyLoading,
|
||||
required this.historyLoaded,
|
||||
required this.myShiftsLoaded,
|
||||
required this.searchQuery,
|
||||
required this.jobType,
|
||||
});
|
||||
@@ -49,6 +51,7 @@ class ShiftsLoaded extends ShiftsState {
|
||||
bool? availableLoaded,
|
||||
bool? historyLoading,
|
||||
bool? historyLoaded,
|
||||
bool? myShiftsLoaded,
|
||||
String? searchQuery,
|
||||
String? jobType,
|
||||
}) {
|
||||
@@ -62,6 +65,7 @@ class ShiftsLoaded extends ShiftsState {
|
||||
availableLoaded: availableLoaded ?? this.availableLoaded,
|
||||
historyLoading: historyLoading ?? this.historyLoading,
|
||||
historyLoaded: historyLoaded ?? this.historyLoaded,
|
||||
myShiftsLoaded: myShiftsLoaded ?? this.myShiftsLoaded,
|
||||
searchQuery: searchQuery ?? this.searchQuery,
|
||||
jobType: jobType ?? this.jobType,
|
||||
);
|
||||
@@ -78,6 +82,7 @@ class ShiftsLoaded extends ShiftsState {
|
||||
availableLoaded,
|
||||
historyLoading,
|
||||
historyLoaded,
|
||||
myShiftsLoaded,
|
||||
searchQuery,
|
||||
jobType,
|
||||
];
|
||||
|
||||
@@ -21,6 +21,7 @@ class ShiftsPage extends StatefulWidget {
|
||||
class _ShiftsPageState extends State<ShiftsPage> {
|
||||
late String _activeTab;
|
||||
DateTime? _selectedDate;
|
||||
bool _prioritizeFind = false;
|
||||
final ShiftsBloc _bloc = Modular.get<ShiftsBloc>();
|
||||
|
||||
@override
|
||||
@@ -28,12 +29,22 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
super.initState();
|
||||
_activeTab = widget.initialTab ?? 'myshifts';
|
||||
_selectedDate = widget.selectedDate;
|
||||
_bloc.add(LoadShiftsEvent());
|
||||
print('ShiftsPage init: initialTab=$_activeTab');
|
||||
_prioritizeFind = widget.initialTab == 'find';
|
||||
if (_prioritizeFind) {
|
||||
_bloc.add(LoadFindFirstEvent());
|
||||
} else {
|
||||
_bloc.add(LoadShiftsEvent());
|
||||
}
|
||||
if (_activeTab == 'history') {
|
||||
print('ShiftsPage init: loading history tab');
|
||||
_bloc.add(LoadHistoryShiftsEvent());
|
||||
}
|
||||
if (_activeTab == 'find') {
|
||||
_bloc.add(LoadAvailableShiftsEvent());
|
||||
print('ShiftsPage init: entering find tab (not loaded yet)');
|
||||
if (!_prioritizeFind) {
|
||||
_bloc.add(LoadAvailableShiftsEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +54,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
if (widget.initialTab != null && widget.initialTab != _activeTab) {
|
||||
setState(() {
|
||||
_activeTab = widget.initialTab!;
|
||||
_prioritizeFind = widget.initialTab == 'find';
|
||||
});
|
||||
}
|
||||
if (widget.selectedDate != null && widget.selectedDate != _selectedDate) {
|
||||
@@ -86,6 +98,10 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
final bool historyLoaded = (state is ShiftsLoaded)
|
||||
? state.historyLoaded
|
||||
: false;
|
||||
final bool myShiftsLoaded = (state is ShiftsLoaded)
|
||||
? state.myShiftsLoaded
|
||||
: false;
|
||||
final bool blockTabsForFind = _prioritizeFind && !availableLoaded;
|
||||
|
||||
// Note: "filteredJobs" logic moved to FindShiftsTab
|
||||
// Note: Calendar logic moved to MyShiftsTab
|
||||
@@ -124,7 +140,8 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
"My Shifts",
|
||||
UiIcons.calendar,
|
||||
myShifts.length,
|
||||
enabled: true,
|
||||
showCount: myShiftsLoaded,
|
||||
enabled: !blockTabsForFind,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildTab(
|
||||
@@ -143,7 +160,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
UiIcons.clock,
|
||||
historyShifts.length,
|
||||
showCount: historyLoaded,
|
||||
enabled: baseLoaded,
|
||||
enabled: !blockTabsForFind && baseLoaded,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -22,6 +22,12 @@ class _FindShiftsTabState extends State<FindShiftsTab> {
|
||||
String _searchQuery = '';
|
||||
String _jobType = 'all';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
print('FindShiftsTab init: tab entered, data pending');
|
||||
}
|
||||
|
||||
Widget _buildFilterTab(String id, String label) {
|
||||
final isSelected = _jobType == id;
|
||||
return GestureDetector(
|
||||
|
||||
Reference in New Issue
Block a user