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(
|
await _dataConnect.createApplication(
|
||||||
shiftId: shiftId,
|
shiftId: shiftId,
|
||||||
staffId: staffId,
|
staffId: staffId,
|
||||||
roleId: role.id,
|
roleId: role.roleId,
|
||||||
status: isInstantBook ? dc.ApplicationStatus.ACCEPTED : dc.ApplicationStatus.PENDING,
|
status: isInstantBook ? dc.ApplicationStatus.ACCEPTED : dc.ApplicationStatus.PENDING,
|
||||||
origin: dc.ApplicationOrigin.STAFF,
|
origin: dc.ApplicationOrigin.STAFF,
|
||||||
).execute();
|
).execute();
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
|||||||
myShifts: myShiftsResult,
|
myShifts: myShiftsResult,
|
||||||
pendingShifts: pendingResult,
|
pendingShifts: pendingResult,
|
||||||
cancelledShifts: cancelledResult,
|
cancelledShifts: cancelledResult,
|
||||||
availableShifts: availableResult,
|
availableShifts: _filterPastShifts(availableResult),
|
||||||
historyShifts: historyResult,
|
historyShifts: historyResult,
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
jobType: 'all',
|
jobType: 'all',
|
||||||
@@ -81,7 +81,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
|||||||
));
|
));
|
||||||
|
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
availableShifts: result,
|
availableShifts: _filterPastShifts(result),
|
||||||
searchQuery: event.query ?? currentState.searchQuery,
|
searchQuery: event.query ?? currentState.searchQuery,
|
||||||
jobType: event.jobType ?? currentState.jobType,
|
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