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)
|
||||
|
||||
Reference in New Issue
Block a user