feat: Update roleId assignment and filter past shifts in ShiftsBloc
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user