feat: smart re-assignment with cancellation source tracking
Add cancelled_by, cancellation_source (organiser|volunteer|system), and cancelled_at columns to shift_assignments. Cancel flow now records who cancelled and why. Assign flow reactivates existing cancelled/rejected records instead of creating duplicates, preventing UNIQUE constraint violations. Assignable-persons endpoint returns previous_assignment data for contextual UI indicators. Frontend shows cancellation source labels, previous assignment history in assign dialog, and "Opnieuw toewijzen" buttons with volunteer-cancelled confirmation dialogs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -120,7 +120,7 @@ final class ShiftAssignmentController extends Controller
|
||||
->get()
|
||||
->keyBy('person_id');
|
||||
|
||||
// Get all assignments for THIS shift in one query
|
||||
// Get active (non-cancelled/rejected) assignments for THIS shift
|
||||
$alreadyAssigned = ShiftAssignment::where('shift_id', $shiftId)
|
||||
->whereNotIn('status', [
|
||||
ShiftAssignmentStatus::REJECTED,
|
||||
@@ -129,15 +129,25 @@ final class ShiftAssignmentController extends Controller
|
||||
->pluck('person_id')
|
||||
->flip();
|
||||
|
||||
// Get previous cancelled/rejected assignments on THIS shift
|
||||
$previousAssignments = ShiftAssignment::where('shift_id', $shiftId)
|
||||
->whereIn('status', [
|
||||
ShiftAssignmentStatus::CANCELLED,
|
||||
ShiftAssignmentStatus::REJECTED,
|
||||
])
|
||||
->get()
|
||||
->keyBy('person_id');
|
||||
|
||||
$persons = Person::where('event_id', $festivalEventId)
|
||||
->where('status', PersonStatus::APPROVED)
|
||||
->with('crowdType')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(function (Person $person) use ($conflicts, $alreadyAssigned, $shiftId) {
|
||||
->map(function (Person $person) use ($conflicts, $alreadyAssigned, $previousAssignments, $shiftId) {
|
||||
$isAlreadyAssigned = $alreadyAssigned->has($person->id);
|
||||
$conflict = $conflicts->get($person->id);
|
||||
$hasConflict = $conflict && $conflict->shift_id !== $shiftId;
|
||||
$previous = $previousAssignments->get($person->id);
|
||||
|
||||
return [
|
||||
'id' => $person->id,
|
||||
@@ -158,6 +168,12 @@ final class ShiftAssignmentController extends Controller
|
||||
'time' => $conflict->shift->timeSlot->start_time
|
||||
. '–' . $conflict->shift->timeSlot->end_time,
|
||||
] : null,
|
||||
'previous_assignment' => $previous ? [
|
||||
'status' => $previous->status->value,
|
||||
'cancellation_source' => $previous->cancellation_source?->value,
|
||||
'cancelled_at' => $previous->cancelled_at?->toIso8601String(),
|
||||
'rejection_reason' => $previous->rejection_reason,
|
||||
] : null,
|
||||
];
|
||||
})
|
||||
->sortBy([
|
||||
|
||||
@@ -23,6 +23,9 @@ final class ShiftAssignmentResource extends JsonResource
|
||||
'approved_by' => $this->approved_by,
|
||||
'approved_at' => $this->approved_at?->toIso8601String(),
|
||||
'rejection_reason' => $this->rejection_reason,
|
||||
'cancelled_by' => $this->cancelled_by,
|
||||
'cancellation_source' => $this->cancellation_source?->value,
|
||||
'cancelled_at' => $this->cancelled_at?->toIso8601String(),
|
||||
'hours_expected' => $this->hours_expected,
|
||||
'hours_completed' => $this->hours_completed,
|
||||
'checked_in_at' => $this->checked_in_at?->toIso8601String(),
|
||||
|
||||
Reference in New Issue
Block a user