feat: inform user about automatic reassignments or reset selections

This commit is contained in:
Björn Fromme
2025-10-02 17:57:56 +02:00
parent 8e43edcbaf
commit fba9edc931
10 changed files with 173 additions and 5 deletions
@@ -131,6 +131,9 @@ class CreateStep2Controller extends AbstractController
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
// Collect notifications from all participants
$notifications = $this->collectParticipantNotifications($bookingCreateDto);
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingCreateDto);
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
@@ -139,7 +142,7 @@ class CreateStep2Controller extends AbstractController
// The DTO is now updated with the latest selection and submitted data has been cleaned.
// We can now render the blocks with the fresh data.
return $this->htmxOobResponse(
$response = $this->htmxOobResponse(
'booking/create_step_2.html.twig',
['participants_form', 'booking_summary'],
[
@@ -152,6 +155,15 @@ class CreateStep2Controller extends AbstractController
'groupedSelectedRooms' => $groupedSelectedRooms,
]
);
// Add notifications to HTMX trigger header if any exist
if ([] !== $notifications) {
$response->headers->set('HX-Trigger', json_encode([
'showNotifications' => ['notifications' => $notifications],
]));
}
return $response;
}
/**
@@ -233,4 +245,28 @@ class CreateStep2Controller extends AbstractController
$this->roomAssignmentService->assignParticipantsToRooms($bookingCreateDto);
}
}
/**
* Collects all notifications from participants and clears them.
*
* @param BookingCreateDto $bookingCreateDto The booking DTO containing participants
*
* @return array<array{type: string, message: string}> Array of notification messages
*/
private function collectParticipantNotifications(BookingCreateDto $bookingCreateDto): array
{
$notifications = [];
foreach ($bookingCreateDto->participants as $participant) {
if ([] !== $participant->notifications) {
foreach ($participant->notifications as $notification) {
$notifications[] = $notification;
}
// Clear notifications after collection
$participant->notifications = [];
}
}
return $notifications;
}
}