feat: conditionally render room assignment field in participant edit form
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates based on the booking workflow mode.
|
||||
*
|
||||
* Used to apply field states that should only be active in a specific mode
|
||||
* (create or edit), such as making room assignments readonly in edit mode.
|
||||
*/
|
||||
class BookingModeCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* @param string $mode The mode to check against (BookingDto::MODE_CREATE or BookingDto::MODE_EDIT)
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly string $mode,
|
||||
) {
|
||||
if (BookingDto::MODE_CREATE !== $mode && BookingDto::MODE_EDIT !== $mode) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid mode "%s". Must be one of: %s, %s', $mode, BookingDto::MODE_CREATE, BookingDto::MODE_EDIT));
|
||||
}
|
||||
}
|
||||
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
return $this->mode === $bookingDto->getMode();
|
||||
}
|
||||
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return sprintf('Returns true when booking is in %s mode', $this->mode);
|
||||
}
|
||||
}
|
||||
@@ -263,8 +263,11 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
'required' => new ApplicantCondition(),
|
||||
];
|
||||
|
||||
// Render assignedRoomId field as static text when only one room type is selected (auto-assigned by RoomAssignmentService)
|
||||
// Room assignment field:
|
||||
// - Hidden until date of birth is provided (age determines room eligibility, e.g., Baby rooms)
|
||||
// - Rendered as static text when only one room type is selected (auto-assigned by RoomAssignmentService)
|
||||
$this->fieldStateConditions['assignedRoomId'] = [
|
||||
'hidden' => CompositeCondition::not($dateOfBirthProvidedCondition),
|
||||
'static_text' => new SingleRoomTypeCondition(),
|
||||
];
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ declare(strict_types=1);
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Abstract\AbstractFieldStateProvider;
|
||||
use App\Form\Service\Condition\AdditionalServicesMutabilityCondition;
|
||||
use App\Form\Service\Condition\ApplicantCondition;
|
||||
use App\Form\Service\Condition\AuthenticatedUserPersonalDataCondition;
|
||||
use App\Form\Service\Condition\BookingModeCondition;
|
||||
use App\Form\Service\Condition\CompositeCondition;
|
||||
use App\Form\Service\Condition\DateOfBirthProvidedCondition;
|
||||
use App\Form\Service\Condition\FieldValueCondition;
|
||||
@@ -16,7 +18,6 @@ use App\Form\Service\Condition\PersonalDataMutabilityCondition;
|
||||
use App\Form\Service\Condition\PickupsMutabilityCondition;
|
||||
use App\Form\Service\Condition\RentalSelectionCondition;
|
||||
use App\Form\Service\Condition\ServiceSubTypeCondition;
|
||||
use App\Form\Service\Condition\SingleRoomTypeCondition;
|
||||
use App\Form\Service\Condition\SkiPassSelectionCondition;
|
||||
use App\Form\Service\Condition\TransportationServicesMutabilityCondition;
|
||||
|
||||
@@ -97,10 +98,10 @@ class EditFieldStateProvider extends AbstractFieldStateProvider
|
||||
'static_text' => $personalDataHiddenCondition,
|
||||
];
|
||||
|
||||
// Render assignedRoomId field as static text when only one room type is selected (auto-assigned by RoomAssignmentService)
|
||||
// Same logic as create mode - render as static text when only one room type available
|
||||
// Room assignments are fixed in edit mode - always render as static text
|
||||
// The assignedRoomId value passes through unchanged from the loaded booking data
|
||||
$this->fieldStateConditions['assignedRoomId'] = [
|
||||
'static_text' => new SingleRoomTypeCondition(),
|
||||
'static_text' => new BookingModeCondition(BookingDto::MODE_EDIT),
|
||||
];
|
||||
|
||||
// Conditional visibility for service fields (same as create flow)
|
||||
|
||||
@@ -134,22 +134,24 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Room assignment #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %}
|
||||
{% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %}
|
||||
{{ macros.field_or_static(form, 'assignedRoomId', 'Zimmer', roomLabel, bookingDto, participantIndex, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{% if form.remarksRoom is defined %}
|
||||
{{ form_row(form.remarksRoom) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{# Room assignment - hidden until date of birth is provided, or shown as static text in edit mode #}
|
||||
{% if form.assignedRoomId is defined or is_static_text('assignedRoomId', bookingDto, participantIndex) %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %}
|
||||
{% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %}
|
||||
{{ macros.field_or_static(form, 'assignedRoomId', 'Zimmer', roomLabel, bookingDto, participantIndex, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{% if form.remarksRoom is defined %}
|
||||
{{ form_row(form.remarksRoom) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Eligibility checks #}
|
||||
{% set participantData = form.vars.data.participant %}
|
||||
|
||||
Reference in New Issue
Block a user