feat(shifts): implement submit for approval functionality
- Added `submitForApproval` method to `ShiftsRepositoryInterface` and its implementation in `ShiftsRepositoryImpl`. - Created `SubmitForApprovalUseCase` to handle the submission logic. - Updated `ShiftsBloc` to handle `SubmitForApprovalEvent` and manage submission state. - Enhanced `HistoryShiftsTab` and `MyShiftsTab` to support submission actions and display appropriate UI feedback. - Refactored date utilities for better calendar management and filtering of past shifts. - Improved UI components for better spacing and alignment. - Localized success messages for shift submission actions.
This commit is contained in:
@@ -147,6 +147,16 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> submitForApproval(String shiftId, {String? note}) async {
|
||||
await _apiService.post(
|
||||
StaffEndpoints.shiftSubmitForApproval(shiftId),
|
||||
data: <String, dynamic>{
|
||||
if (note != null) 'note': note,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> getProfileCompletion() async {
|
||||
final ApiResponse response =
|
||||
|
||||
@@ -47,4 +47,9 @@ abstract interface class ShiftsRepositoryInterface {
|
||||
|
||||
/// Returns whether the staff profile is complete.
|
||||
Future<bool> getProfileCompletion();
|
||||
|
||||
/// Submits a completed shift for timesheet approval.
|
||||
///
|
||||
/// Only allowed for shifts in CHECKED_OUT or COMPLETED status.
|
||||
Future<void> submitForApproval(String shiftId, {String? note});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:staff_shifts/src/domain/repositories/shifts_repository_interface.dart';
|
||||
|
||||
/// Submits a completed shift for timesheet approval.
|
||||
///
|
||||
/// Delegates to [ShiftsRepositoryInterface.submitForApproval] which calls
|
||||
/// `POST /staff/shifts/:shiftId/submit-for-approval`.
|
||||
class SubmitForApprovalUseCase {
|
||||
/// Creates a [SubmitForApprovalUseCase].
|
||||
SubmitForApprovalUseCase(this.repository);
|
||||
|
||||
/// The shifts repository.
|
||||
final ShiftsRepositoryInterface repository;
|
||||
|
||||
/// Executes the use case.
|
||||
Future<void> call(String shiftId, {String? note}) async {
|
||||
return repository.submitForApproval(shiftId, note: note);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
/// Computes a Friday-based week calendar for the given [weekOffset].
|
||||
///
|
||||
/// Returns a list of 7 [DateTime] values starting from the Friday of the
|
||||
/// week identified by [weekOffset] (0 = current week, negative = past,
|
||||
/// positive = future). Each date is midnight-normalised.
|
||||
List<DateTime> getCalendarDaysForOffset(int weekOffset) {
|
||||
final DateTime now = DateTime.now();
|
||||
final int reactDayIndex = now.weekday == 7 ? 0 : now.weekday;
|
||||
final int daysSinceFriday = (reactDayIndex + 2) % 7;
|
||||
final DateTime start = now
|
||||
.subtract(Duration(days: daysSinceFriday))
|
||||
.add(Duration(days: weekOffset * 7));
|
||||
final DateTime startDate = DateTime(start.year, start.month, start.day);
|
||||
return List<DateTime>.generate(
|
||||
7,
|
||||
(int index) => startDate.add(Duration(days: index)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Filters out [OpenShift] entries whose date is strictly before today.
|
||||
///
|
||||
/// Comparison is done at midnight granularity so shifts scheduled for
|
||||
/// today are always included.
|
||||
List<OpenShift> filterPastOpenShifts(List<OpenShift> shifts) {
|
||||
final DateTime now = DateTime.now();
|
||||
final DateTime today = DateTime(now.year, now.month, now.day);
|
||||
return shifts.where((OpenShift shift) {
|
||||
final DateTime dateOnly = DateTime(
|
||||
shift.date.year,
|
||||
shift.date.month,
|
||||
shift.date.day,
|
||||
);
|
||||
return !dateOnly.isBefore(today);
|
||||
}).toList();
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class ShiftDetailsBloc extends Bloc<ShiftDetailsEvent, ShiftDetailsState>
|
||||
isProfileComplete: isProfileComplete,
|
||||
));
|
||||
} else {
|
||||
emit(const ShiftDetailsError('Shift not found'));
|
||||
emit(const ShiftDetailsError('errors.shift.not_found'));
|
||||
}
|
||||
},
|
||||
onError: (String errorKey) => ShiftDetailsError(errorKey),
|
||||
@@ -74,7 +74,7 @@ class ShiftDetailsBloc extends Bloc<ShiftDetailsEvent, ShiftDetailsState>
|
||||
);
|
||||
emit(
|
||||
ShiftActionSuccess(
|
||||
'Shift successfully booked!',
|
||||
'shift_booked',
|
||||
shiftDate: event.date,
|
||||
),
|
||||
);
|
||||
@@ -91,7 +91,7 @@ class ShiftDetailsBloc extends Bloc<ShiftDetailsEvent, ShiftDetailsState>
|
||||
emit: emit.call,
|
||||
action: () async {
|
||||
await declineShift(event.shiftId);
|
||||
emit(const ShiftActionSuccess('Shift declined'));
|
||||
emit(const ShiftActionSuccess('shift_declined_success'));
|
||||
},
|
||||
onError: (String errorKey) => ShiftDetailsError(errorKey),
|
||||
);
|
||||
|
||||
@@ -14,6 +14,8 @@ import 'package:staff_shifts/src/domain/usecases/get_history_shifts_usecase.dart
|
||||
import 'package:staff_shifts/src/domain/usecases/get_my_shifts_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/get_pending_assignments_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/get_profile_completion_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/submit_for_approval_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/utils/shift_date_utils.dart';
|
||||
|
||||
part 'shifts_event.dart';
|
||||
part 'shifts_state.dart';
|
||||
@@ -31,6 +33,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
required this.getProfileCompletion,
|
||||
required this.acceptShift,
|
||||
required this.declineShift,
|
||||
required this.submitForApproval,
|
||||
}) : super(const ShiftsState()) {
|
||||
on<LoadShiftsEvent>(_onLoadShifts);
|
||||
on<LoadHistoryShiftsEvent>(_onLoadHistoryShifts);
|
||||
@@ -41,6 +44,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
on<CheckProfileCompletionEvent>(_onCheckProfileCompletion);
|
||||
on<AcceptShiftEvent>(_onAcceptShift);
|
||||
on<DeclineShiftEvent>(_onDeclineShift);
|
||||
on<SubmitForApprovalEvent>(_onSubmitForApproval);
|
||||
}
|
||||
|
||||
/// Use case for assigned shifts.
|
||||
@@ -67,6 +71,9 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
/// Use case for declining a shift.
|
||||
final DeclineShiftUseCase declineShift;
|
||||
|
||||
/// Use case for submitting a shift for timesheet approval.
|
||||
final SubmitForApprovalUseCase submitForApproval;
|
||||
|
||||
Future<void> _onLoadShifts(
|
||||
LoadShiftsEvent event,
|
||||
Emitter<ShiftsState> emit,
|
||||
@@ -78,7 +85,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
await handleError(
|
||||
emit: emit.call,
|
||||
action: () async {
|
||||
final List<DateTime> days = _getCalendarDaysForOffset(0);
|
||||
final List<DateTime> days = getCalendarDaysForOffset(0);
|
||||
|
||||
// Load assigned, pending, and cancelled shifts in parallel.
|
||||
final List<Object> results = await Future.wait(<Future<Object>>[
|
||||
@@ -110,6 +117,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
historyLoaded: false,
|
||||
myShiftsLoaded: true,
|
||||
searchQuery: '',
|
||||
clearErrorMessage: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -136,6 +144,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
historyShifts: historyResult,
|
||||
historyLoading: false,
|
||||
historyLoaded: true,
|
||||
clearErrorMessage: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -167,9 +176,10 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
availableShifts: _filterPastOpenShifts(availableResult),
|
||||
availableShifts: filterPastOpenShifts(availableResult),
|
||||
availableLoading: false,
|
||||
availableLoaded: true,
|
||||
clearErrorMessage: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -219,9 +229,10 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ShiftsStatus.loaded,
|
||||
availableShifts: _filterPastOpenShifts(availableResult),
|
||||
availableShifts: filterPastOpenShifts(availableResult),
|
||||
availableLoading: false,
|
||||
availableLoaded: true,
|
||||
clearErrorMessage: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -239,6 +250,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
LoadShiftsForRangeEvent event,
|
||||
Emitter<ShiftsState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(myShifts: const <AssignedShift>[], myShiftsLoaded: false));
|
||||
await handleError(
|
||||
emit: emit.call,
|
||||
action: () async {
|
||||
@@ -251,6 +263,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
status: ShiftsStatus.loaded,
|
||||
myShifts: myShiftsResult,
|
||||
myShiftsLoaded: true,
|
||||
clearErrorMessage: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -281,7 +294,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
availableShifts: _filterPastOpenShifts(result),
|
||||
availableShifts: filterPastOpenShifts(result),
|
||||
searchQuery: search,
|
||||
),
|
||||
);
|
||||
@@ -342,30 +355,37 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState>
|
||||
);
|
||||
}
|
||||
|
||||
/// Gets calendar days for the given week offset (Friday-based week).
|
||||
List<DateTime> _getCalendarDaysForOffset(int weekOffset) {
|
||||
final DateTime now = DateTime.now();
|
||||
final int reactDayIndex = now.weekday == 7 ? 0 : now.weekday;
|
||||
final int daysSinceFriday = (reactDayIndex + 2) % 7;
|
||||
final DateTime start = now
|
||||
.subtract(Duration(days: daysSinceFriday))
|
||||
.add(Duration(days: weekOffset * 7));
|
||||
final DateTime startDate = DateTime(start.year, start.month, start.day);
|
||||
return List<DateTime>.generate(
|
||||
7, (int index) => startDate.add(Duration(days: index)));
|
||||
Future<void> _onSubmitForApproval(
|
||||
SubmitForApprovalEvent event,
|
||||
Emitter<ShiftsState> emit,
|
||||
) async {
|
||||
// Guard: another submission is already in progress.
|
||||
if (state.submittingShiftId != null) return;
|
||||
// Guard: this shift was already submitted.
|
||||
if (state.submittedShiftIds.contains(event.shiftId)) return;
|
||||
|
||||
emit(state.copyWith(submittingShiftId: event.shiftId));
|
||||
await handleError(
|
||||
emit: emit.call,
|
||||
action: () async {
|
||||
await submitForApproval(event.shiftId, note: event.note);
|
||||
emit(
|
||||
state.copyWith(
|
||||
clearSubmittingShiftId: true,
|
||||
clearErrorMessage: true,
|
||||
submittedShiftIds: <String>{
|
||||
...state.submittedShiftIds,
|
||||
event.shiftId,
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
onError: (String errorKey) => state.copyWith(
|
||||
clearSubmittingShiftId: true,
|
||||
status: ShiftsStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Filters out open shifts whose date is in the past.
|
||||
List<OpenShift> _filterPastOpenShifts(List<OpenShift> shifts) {
|
||||
final DateTime now = DateTime.now();
|
||||
final DateTime today = DateTime(now.year, now.month, now.day);
|
||||
return shifts.where((OpenShift shift) {
|
||||
final DateTime dateOnly = DateTime(
|
||||
shift.date.year,
|
||||
shift.date.month,
|
||||
shift.date.day,
|
||||
);
|
||||
return !dateOnly.isBefore(today);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,3 +93,18 @@ class CheckProfileCompletionEvent extends ShiftsEvent {
|
||||
@override
|
||||
List<Object?> get props => <Object?>[];
|
||||
}
|
||||
|
||||
/// Submits a completed shift for timesheet approval.
|
||||
class SubmitForApprovalEvent extends ShiftsEvent {
|
||||
/// Creates a [SubmitForApprovalEvent].
|
||||
const SubmitForApprovalEvent({required this.shiftId, this.note});
|
||||
|
||||
/// The shift row id to submit.
|
||||
final String shiftId;
|
||||
|
||||
/// Optional note to include with the submission.
|
||||
final String? note;
|
||||
|
||||
@override
|
||||
List<Object?> get props => <Object?>[shiftId, note];
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ class ShiftsState extends Equatable {
|
||||
this.searchQuery = '',
|
||||
this.profileComplete,
|
||||
this.errorMessage,
|
||||
this.submittingShiftId,
|
||||
this.submittedShiftIds = const <String>{},
|
||||
});
|
||||
|
||||
/// Current lifecycle status.
|
||||
@@ -65,6 +67,12 @@ class ShiftsState extends Equatable {
|
||||
/// Error message key for display.
|
||||
final String? errorMessage;
|
||||
|
||||
/// The shift ID currently being submitted for approval (null when idle).
|
||||
final String? submittingShiftId;
|
||||
|
||||
/// Set of shift IDs that have been successfully submitted for approval.
|
||||
final Set<String> submittedShiftIds;
|
||||
|
||||
/// Creates a copy with the given fields replaced.
|
||||
ShiftsState copyWith({
|
||||
ShiftsStatus? status,
|
||||
@@ -81,6 +89,10 @@ class ShiftsState extends Equatable {
|
||||
String? searchQuery,
|
||||
bool? profileComplete,
|
||||
String? errorMessage,
|
||||
bool clearErrorMessage = false,
|
||||
String? submittingShiftId,
|
||||
bool clearSubmittingShiftId = false,
|
||||
Set<String>? submittedShiftIds,
|
||||
}) {
|
||||
return ShiftsState(
|
||||
status: status ?? this.status,
|
||||
@@ -96,7 +108,13 @@ class ShiftsState extends Equatable {
|
||||
myShiftsLoaded: myShiftsLoaded ?? this.myShiftsLoaded,
|
||||
searchQuery: searchQuery ?? this.searchQuery,
|
||||
profileComplete: profileComplete ?? this.profileComplete,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
errorMessage: clearErrorMessage
|
||||
? null
|
||||
: (errorMessage ?? this.errorMessage),
|
||||
submittingShiftId: clearSubmittingShiftId
|
||||
? null
|
||||
: (submittingShiftId ?? this.submittingShiftId),
|
||||
submittedShiftIds: submittedShiftIds ?? this.submittedShiftIds,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,5 +134,7 @@ class ShiftsState extends Equatable {
|
||||
searchQuery,
|
||||
profileComplete,
|
||||
errorMessage,
|
||||
submittingShiftId,
|
||||
submittedShiftIds,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,12 +47,6 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
return DateFormat('EEEE, MMMM d, y').format(dt);
|
||||
}
|
||||
|
||||
double _calculateDuration(ShiftDetail detail) {
|
||||
final int minutes = detail.endTime.difference(detail.startTime).inMinutes;
|
||||
final double hours = minutes / 60;
|
||||
return hours < 0 ? hours + 24 : hours;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<ShiftDetailsBloc>(
|
||||
@@ -67,7 +61,7 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
_isApplying = false;
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
message: state.message,
|
||||
message: _translateSuccessKey(context, state.message),
|
||||
type: UiSnackbarType.success,
|
||||
);
|
||||
Modular.to.toShifts(
|
||||
@@ -98,14 +92,8 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
}
|
||||
|
||||
final ShiftDetail detail = state.detail;
|
||||
final dynamic i18n =
|
||||
Translations.of(context).staff_shifts.shift_details;
|
||||
final bool isProfileComplete = state.isProfileComplete;
|
||||
|
||||
final double duration = _calculateDuration(detail);
|
||||
final double hourlyRate = detail.hourlyRateCents / 100;
|
||||
final double estimatedTotal = hourlyRate * duration;
|
||||
|
||||
return Scaffold(
|
||||
appBar: UiAppBar(
|
||||
centerTitle: false,
|
||||
@@ -122,45 +110,46 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(UiConstants.space6),
|
||||
child: UiNoticeBanner(
|
||||
title: 'Complete Your Account',
|
||||
description:
|
||||
'Complete your account to book this shift and start earning',
|
||||
title: context.t.staff_shifts.shift_details
|
||||
.complete_account_title,
|
||||
description: context.t.staff_shifts.shift_details
|
||||
.complete_account_description,
|
||||
icon: UiIcons.sparkles,
|
||||
),
|
||||
),
|
||||
ShiftDetailsHeader(detail: detail),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
ShiftStatsRow(
|
||||
estimatedTotal: estimatedTotal,
|
||||
hourlyRate: hourlyRate,
|
||||
duration: duration,
|
||||
totalLabel: i18n.est_total,
|
||||
hourlyRateLabel: i18n.hourly_rate,
|
||||
hoursLabel: i18n.hours,
|
||||
estimatedTotal: detail.estimatedTotal,
|
||||
hourlyRate: detail.hourlyRate,
|
||||
duration: detail.durationHours,
|
||||
totalLabel: context.t.staff_shifts.shift_details.est_total,
|
||||
hourlyRateLabel: context.t.staff_shifts.shift_details.hourly_rate,
|
||||
hoursLabel: context.t.staff_shifts.shift_details.hours,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
ShiftDateTimeSection(
|
||||
date: detail.date,
|
||||
startTime: detail.startTime,
|
||||
endTime: detail.endTime,
|
||||
shiftDateLabel: i18n.shift_date,
|
||||
clockInLabel: i18n.start_time,
|
||||
clockOutLabel: i18n.end_time,
|
||||
shiftDateLabel: context.t.staff_shifts.shift_details.shift_date,
|
||||
clockInLabel: context.t.staff_shifts.shift_details.start_time,
|
||||
clockOutLabel: context.t.staff_shifts.shift_details.end_time,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
ShiftLocationSection(
|
||||
location: detail.location,
|
||||
address: detail.address ?? '',
|
||||
locationLabel: i18n.location,
|
||||
tbdLabel: i18n.tbd,
|
||||
getDirectionLabel: i18n.get_direction,
|
||||
locationLabel: context.t.staff_shifts.shift_details.location,
|
||||
tbdLabel: context.t.staff_shifts.shift_details.tbd,
|
||||
getDirectionLabel: context.t.staff_shifts.shift_details.get_direction,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
if (detail.description != null &&
|
||||
detail.description!.isNotEmpty)
|
||||
ShiftDescriptionSection(
|
||||
description: detail.description!,
|
||||
descriptionLabel: i18n.job_description,
|
||||
descriptionLabel: context.t.staff_shifts.shift_details.job_description,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -190,13 +179,11 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
}
|
||||
|
||||
void _bookShift(BuildContext context, ShiftDetail detail) {
|
||||
final dynamic i18n =
|
||||
Translations.of(context).staff_shifts.shift_details.book_dialog;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) => AlertDialog(
|
||||
title: Text(i18n.title as String),
|
||||
content: Text(i18n.message as String),
|
||||
title: Text(context.t.staff_shifts.shift_details.book_dialog.title),
|
||||
content: Text(context.t.staff_shifts.shift_details.book_dialog.message),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Modular.to.popSafe(),
|
||||
@@ -228,14 +215,12 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
if (_actionDialogOpen) return;
|
||||
_actionDialogOpen = true;
|
||||
_isApplying = true;
|
||||
final dynamic i18n =
|
||||
Translations.of(context).staff_shifts.shift_details.applying_dialog;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext ctx) => AlertDialog(
|
||||
title: Text(i18n.title as String),
|
||||
title: Text(context.t.staff_shifts.shift_details.applying_dialog.title),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
@@ -250,7 +235,7 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
style: UiTypography.body2b.textPrimary,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const SizedBox(height: UiConstants.space1),
|
||||
Text(
|
||||
'${_formatDate(detail.date)} \u2022 ${_formatTime(detail.startTime)} - ${_formatTime(detail.endTime)}',
|
||||
style: UiTypography.body3r.textSecondary,
|
||||
@@ -270,6 +255,18 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
_actionDialogOpen = false;
|
||||
}
|
||||
|
||||
/// Translates a success message key to a localized string.
|
||||
String _translateSuccessKey(BuildContext context, String key) {
|
||||
switch (key) {
|
||||
case 'shift_booked':
|
||||
return context.t.staff_shifts.shift_details.shift_booked;
|
||||
case 'shift_declined_success':
|
||||
return context.t.staff_shifts.shift_details.shift_declined_success;
|
||||
default:
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
void _showEligibilityErrorDialog(BuildContext context) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
@@ -288,16 +285,16 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
],
|
||||
),
|
||||
content: Text(
|
||||
'You are missing required certifications or documents to claim this shift. Please upload them to continue.',
|
||||
context.t.staff_shifts.shift_details.missing_certifications,
|
||||
style: UiTypography.body2r.textSecondary,
|
||||
),
|
||||
actions: <Widget>[
|
||||
UiButton.secondary(
|
||||
text: 'Cancel',
|
||||
text: Translations.of(context).common.cancel,
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
),
|
||||
UiButton.primary(
|
||||
text: 'Go to Certificates',
|
||||
text: context.t.staff_shifts.shift_details.go_to_certificates,
|
||||
onPressed: () {
|
||||
Modular.to.popSafe();
|
||||
Modular.to.toCertificates();
|
||||
|
||||
@@ -12,10 +12,15 @@ import 'package:staff_shifts/src/presentation/widgets/tabs/my_shifts_tab.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/tabs/find_shifts_tab.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/tabs/history_shifts_tab.dart';
|
||||
|
||||
/// Tabbed page for browsing staff shifts (My Shifts, Find Work, History).
|
||||
///
|
||||
/// Manages tab state locally and delegates data loading to [ShiftsBloc].
|
||||
class ShiftsPage extends StatefulWidget {
|
||||
final ShiftTabType? initialTab;
|
||||
final DateTime? selectedDate;
|
||||
final bool refreshAvailable;
|
||||
/// Creates a [ShiftsPage].
|
||||
///
|
||||
/// [initialTab] selects the active tab on first render.
|
||||
/// [selectedDate] pre-selects a calendar date in the My Shifts tab.
|
||||
/// [refreshAvailable] triggers a forced reload of available shifts.
|
||||
const ShiftsPage({
|
||||
super.key,
|
||||
this.initialTab,
|
||||
@@ -23,6 +28,15 @@ class ShiftsPage extends StatefulWidget {
|
||||
this.refreshAvailable = false,
|
||||
});
|
||||
|
||||
/// The tab to display on initial render. Defaults to [ShiftTabType.find].
|
||||
final ShiftTabType? initialTab;
|
||||
|
||||
/// Optional date to pre-select in the My Shifts calendar.
|
||||
final DateTime? selectedDate;
|
||||
|
||||
/// When true, forces a refresh of available shifts on load.
|
||||
final bool refreshAvailable;
|
||||
|
||||
@override
|
||||
State<ShiftsPage> createState() => _ShiftsPageState();
|
||||
}
|
||||
@@ -251,6 +265,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
pendingAssignments: pendingAssignments,
|
||||
cancelledShifts: cancelledShifts,
|
||||
initialDate: _selectedDate,
|
||||
submittedShiftIds: state.submittedShiftIds,
|
||||
);
|
||||
case ShiftTabType.find:
|
||||
if (availableLoading) {
|
||||
@@ -264,7 +279,10 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
if (historyLoading) {
|
||||
return const ShiftsPageSkeleton();
|
||||
}
|
||||
return HistoryShiftsTab(historyShifts: historyShifts);
|
||||
return HistoryShiftsTab(
|
||||
historyShifts: historyShifts,
|
||||
submittedShiftIds: state.submittedShiftIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +351,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
|
||||
),
|
||||
),
|
||||
if (showCount) ...[
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: UiConstants.space1),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: UiConstants.space1,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:core_localization/core_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
@@ -107,7 +108,7 @@ class ShiftAssignmentCard extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
const Icon(UiIcons.calendar,
|
||||
size: 12, color: UiColors.iconSecondary),
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: UiConstants.space1),
|
||||
Text(
|
||||
_formatDate(assignment.startTime),
|
||||
style: UiTypography.footnote1r.textSecondary,
|
||||
@@ -115,19 +116,19 @@ class ShiftAssignmentCard extends StatelessWidget {
|
||||
const SizedBox(width: UiConstants.space3),
|
||||
const Icon(UiIcons.clock,
|
||||
size: 12, color: UiColors.iconSecondary),
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: UiConstants.space1),
|
||||
Text(
|
||||
'${_formatTime(assignment.startTime)} - ${_formatTime(assignment.endTime)}',
|
||||
style: UiTypography.footnote1r.textSecondary,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const SizedBox(height: UiConstants.space1),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
const Icon(UiIcons.mapPin,
|
||||
size: 12, color: UiColors.iconSecondary),
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: UiConstants.space1),
|
||||
Expanded(
|
||||
child: Text(
|
||||
assignment.location,
|
||||
@@ -160,7 +161,10 @@ class ShiftAssignmentCard extends StatelessWidget {
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: UiColors.destructive,
|
||||
),
|
||||
child: Text('Decline', style: UiTypography.body2m.textError),
|
||||
child: Text(
|
||||
context.t.staff_shifts.shift_details.decline,
|
||||
style: UiTypography.body2m.textError,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: UiConstants.space2),
|
||||
@@ -178,14 +182,17 @@ class ShiftAssignmentCard extends StatelessWidget {
|
||||
),
|
||||
child: isConfirming
|
||||
? const SizedBox(
|
||||
height: 16,
|
||||
width: 16,
|
||||
height: UiConstants.space4,
|
||||
width: UiConstants.space4,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: UiColors.white,
|
||||
),
|
||||
)
|
||||
: Text('Accept', style: UiTypography.body2m.white),
|
||||
: Text(
|
||||
context.t.staff_shifts.shift_details.accept_shift,
|
||||
style: UiTypography.body2m.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
import 'package:core_localization/core_localization.dart';
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart' show ReadContext;
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
import 'package:staff_shifts/src/presentation/blocs/shifts/shifts_bloc.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/shared/empty_state_view.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/shift_card.dart';
|
||||
|
||||
/// Tab displaying completed shift history.
|
||||
class HistoryShiftsTab extends StatelessWidget {
|
||||
/// Creates a [HistoryShiftsTab].
|
||||
const HistoryShiftsTab({super.key, required this.historyShifts});
|
||||
const HistoryShiftsTab({
|
||||
super.key,
|
||||
required this.historyShifts,
|
||||
this.submittedShiftIds = const <String>{},
|
||||
});
|
||||
|
||||
/// Completed shifts.
|
||||
final List<CompletedShift> historyShifts;
|
||||
|
||||
/// Set of shift IDs that have been successfully submitted for approval.
|
||||
final Set<String> submittedShiftIds;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (historyShifts.isEmpty) {
|
||||
@@ -32,14 +41,31 @@ class HistoryShiftsTab extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
const SizedBox(height: UiConstants.space5),
|
||||
...historyShifts.map(
|
||||
(CompletedShift shift) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: UiConstants.space3),
|
||||
child: ShiftCard(
|
||||
data: ShiftCardData.fromCompleted(shift),
|
||||
onTap: () =>
|
||||
Modular.to.toShiftDetailsById(shift.shiftId),
|
||||
),
|
||||
),
|
||||
(CompletedShift shift) {
|
||||
final bool isSubmitted =
|
||||
submittedShiftIds.contains(shift.shiftId);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: UiConstants.space3),
|
||||
child: ShiftCard(
|
||||
data: ShiftCardData.fromCompleted(shift),
|
||||
onTap: () =>
|
||||
Modular.to.toShiftDetailsById(shift.shiftId),
|
||||
showApprovalAction: !isSubmitted,
|
||||
isSubmitted: isSubmitted,
|
||||
onSubmitForApproval: () {
|
||||
ReadContext(context).read<ShiftsBloc>().add(
|
||||
SubmitForApprovalEvent(shiftId: shift.shiftId),
|
||||
);
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
message: context.t.staff_shifts
|
||||
.my_shift_card.timesheet_submitted,
|
||||
type: UiSnackbarType.success,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: UiConstants.space32),
|
||||
],
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
import 'package:staff_shifts/src/domain/utils/shift_date_utils.dart';
|
||||
import 'package:staff_shifts/src/presentation/blocs/shifts/shifts_bloc.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/shared/empty_state_view.dart';
|
||||
import 'package:staff_shifts/src/presentation/widgets/shift_card.dart';
|
||||
@@ -20,6 +21,7 @@ class MyShiftsTab extends StatefulWidget {
|
||||
required this.pendingAssignments,
|
||||
required this.cancelledShifts,
|
||||
this.initialDate,
|
||||
this.submittedShiftIds = const <String>{},
|
||||
});
|
||||
|
||||
/// Assigned shifts for the current week.
|
||||
@@ -34,6 +36,9 @@ class MyShiftsTab extends StatefulWidget {
|
||||
/// Initial date to select in the calendar.
|
||||
final DateTime? initialDate;
|
||||
|
||||
/// Set of shift IDs that have been successfully submitted for approval.
|
||||
final Set<String> submittedShiftIds;
|
||||
|
||||
@override
|
||||
State<MyShiftsTab> createState() => _MyShiftsTabState();
|
||||
}
|
||||
@@ -42,9 +47,6 @@ class _MyShiftsTabState extends State<MyShiftsTab> {
|
||||
DateTime _selectedDate = DateTime.now();
|
||||
int _weekOffset = 0;
|
||||
|
||||
/// Tracks which completed-shift cards have been submitted locally.
|
||||
final Set<String> _submittedShiftIds = <String>{};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -90,20 +92,7 @@ class _MyShiftsTabState extends State<MyShiftsTab> {
|
||||
});
|
||||
}
|
||||
|
||||
List<DateTime> _getCalendarDays() {
|
||||
final DateTime now = DateTime.now();
|
||||
final int reactDayIndex = now.weekday == 7 ? 0 : now.weekday;
|
||||
final int daysSinceFriday = (reactDayIndex + 2) % 7;
|
||||
final DateTime start = now
|
||||
.subtract(Duration(days: daysSinceFriday))
|
||||
.add(Duration(days: _weekOffset * 7));
|
||||
final DateTime startDate =
|
||||
DateTime(start.year, start.month, start.day);
|
||||
return List<DateTime>.generate(
|
||||
7,
|
||||
(int index) => startDate.add(Duration(days: index)),
|
||||
);
|
||||
}
|
||||
List<DateTime> _getCalendarDays() => getCalendarDaysForOffset(_weekOffset);
|
||||
|
||||
void _loadShiftsForCurrentWeek() {
|
||||
final List<DateTime> calendarDays = _getCalendarDays();
|
||||
@@ -402,7 +391,7 @@ class _MyShiftsTabState extends State<MyShiftsTab> {
|
||||
final bool isCompleted =
|
||||
shift.status == AssignmentStatus.completed;
|
||||
final bool isSubmitted =
|
||||
_submittedShiftIds.contains(shift.shiftId);
|
||||
widget.submittedShiftIds.contains(shift.shiftId);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
@@ -415,9 +404,11 @@ class _MyShiftsTabState extends State<MyShiftsTab> {
|
||||
showApprovalAction: isCompleted,
|
||||
isSubmitted: isSubmitted,
|
||||
onSubmitForApproval: () {
|
||||
setState(() {
|
||||
_submittedShiftIds.add(shift.shiftId);
|
||||
});
|
||||
ReadContext(context).read<ShiftsBloc>().add(
|
||||
SubmitForApprovalEvent(
|
||||
shiftId: shift.shiftId,
|
||||
),
|
||||
);
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
message: context.t.staff_shifts
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:staff_shifts/src/domain/usecases/get_profile_completion_usecase.
|
||||
import 'package:staff_shifts/src/domain/usecases/get_shift_details_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/accept_shift_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/decline_shift_usecase.dart';
|
||||
import 'package:staff_shifts/src/domain/usecases/submit_for_approval_usecase.dart';
|
||||
import 'package:staff_shifts/src/presentation/blocs/shifts/shifts_bloc.dart';
|
||||
import 'package:staff_shifts/src/presentation/blocs/shift_details/shift_details_bloc.dart';
|
||||
import 'package:staff_shifts/src/presentation/utils/shift_tab_type.dart';
|
||||
@@ -45,6 +46,9 @@ class StaffShiftsModule extends Module {
|
||||
i.addLazySingleton(ApplyForShiftUseCase.new);
|
||||
i.addLazySingleton(GetShiftDetailUseCase.new);
|
||||
i.addLazySingleton(GetProfileCompletionUseCase.new);
|
||||
i.addLazySingleton(
|
||||
() => SubmitForApprovalUseCase(i.get<ShiftsRepositoryInterface>()),
|
||||
);
|
||||
|
||||
// BLoC
|
||||
i.add(
|
||||
@@ -57,6 +61,7 @@ class StaffShiftsModule extends Module {
|
||||
getProfileCompletion: i.get(),
|
||||
acceptShift: i.get(),
|
||||
declineShift: i.get(),
|
||||
submitForApproval: i.get(),
|
||||
),
|
||||
);
|
||||
i.add(
|
||||
|
||||
Reference in New Issue
Block a user