feat: Update roleId assignment and filter past shifts in ShiftsBloc

This commit is contained in:
Achintha Isuru
2026-01-31 21:04:08 -05:00
parent 0b38383aab
commit 144976de00
2 changed files with 16 additions and 3 deletions

View File

@@ -246,7 +246,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
await _dataConnect.createApplication(
shiftId: shiftId,
staffId: staffId,
roleId: role.id,
roleId: role.roleId,
status: isInstantBook ? dc.ApplicationStatus.ACCEPTED : dc.ApplicationStatus.PENDING,
origin: dc.ApplicationOrigin.STAFF,
).execute();

View File

@@ -55,7 +55,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
myShifts: myShiftsResult,
pendingShifts: pendingResult,
cancelledShifts: cancelledResult,
availableShifts: availableResult,
availableShifts: _filterPastShifts(availableResult),
historyShifts: historyResult,
searchQuery: '',
jobType: 'all',
@@ -81,7 +81,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
));
emit(currentState.copyWith(
availableShifts: result,
availableShifts: _filterPastShifts(result),
searchQuery: event.query ?? currentState.searchQuery,
jobType: event.jobType ?? currentState.jobType,
));
@@ -90,4 +90,17 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
}
}
}
List<Shift> _filterPastShifts(List<Shift> shifts) {
final now = DateTime.now();
return shifts.where((shift) {
if (shift.date.isEmpty) return false;
try {
final shiftDate = DateTime.parse(shift.date);
return shiftDate.isAfter(now);
} catch (_) {
return false;
}
}).toList();
}
}