Skip to content

Commit

Permalink
feat: Move file uploader above the send button (dvsa/olcs-selfserve#98)
Browse files Browse the repository at this point in the history
* feat: Move file uploader above the send button

* fix: Remove guidance from reply

* fix: Controller tests

* fix: Whitespace
  • Loading branch information
wadedvsa authored Mar 15, 2024
1 parent 40d63cc commit 6df11f8
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public function addAction(): ViewModel
$form = $this->formHelperService->createForm(CreateForm::class, true, false);
$form->get('correlationId')->setValue(sha1(microtime()));

$fileFieldset = $form->get('form-actions')->get('file');
$fileFieldset->setAttribute('class', $fileFieldset->getAttribute('class') . ' last');

$isPost = $this->getRequest()->isPost();
$canUploadFiles = $this->getCurrentOrganisation()['isMessagingFileUploadEnabled'];
if (!$canUploadFiles) {
Expand Down Expand Up @@ -163,13 +166,13 @@ private function mapFormDataToCommand(\Laminas\Form\Form $form): Create
{
$data = $form->getData();
$processedData = [
'messageSubject' => $data['form-actions']['messageSubject'],
'messageContent' => $data['form-actions']['messageContent'],
'messageSubject' => $data['form-actions']['inputs']['messageSubject'],
'messageContent' => $data['form-actions']['inputs']['messageContent'],
'correlationId' => $data['correlationId'],
];

$appOrLicNoPrefix = substr($data['form-actions']['appOrLicNo'], 0, 1);
$appOrLicNoSuffix = substr($data['form-actions']['appOrLicNo'], 1);
$appOrLicNoPrefix = substr($data['form-actions']['inputs']['appOrLicNo'], 0, 1);
$appOrLicNoSuffix = substr($data['form-actions']['inputs']['appOrLicNo'], 1);
switch ($appOrLicNoPrefix) {
case MessagingAppOrLicNo::PREFIX_LICENCE:
$processedData['licence'] = $appOrLicNoSuffix;
Expand Down Expand Up @@ -216,6 +219,8 @@ public function viewAction()

$table = $this->tableFactory->buildTable('messages-view', $messages, $params);

$form->get('form-actions')->get('actions')->remove('guidance');

$canUploadFiles = $this->getCurrentOrganisation()['isMessagingFileUploadEnabled'];
if (!$canUploadFiles) {
$form->get('form-actions')->remove('file');
Expand Down Expand Up @@ -270,7 +275,7 @@ protected function parseReply(ViewModel $view, Form $form)
[
'conversation' => $this->params()->fromRoute('conversationId'),
'correlationId' => $this->getRequest()->getPost('correlationId'),
'messageContent' => $form->get('form-actions')->get('reply')->getValue(),
'messageContent' => $form->get('form-actions')->get('inputs')->get('reply')->getValue(),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Olcs\Form\Model\Fieldset\Message;

use Common\Form\Elements\InputFilters\ActionButton;
use Common\Form\Elements\Types\GuidanceTranslated;
use Laminas\Form\Annotation as Form;

class Actions
{
/**
* @Form\Attributes({
* "value": "markup-messaging-new-conversation-timeframe",
* "id": "guidance"
* })
* @Form\Type(GuidanceTranslated::class)
*/
public ?GuidanceTranslated $guidance = null;

/**
* @Form\Attributes({
* "type": "submit",
* "data-module": "govuk-button",
* "class": "govuk-button govuk-button--default",
* "id": "send"
* })
* @Form\Options({
* "label": "Send message"
* })
* @Form\Type(ActionButton::class)
*/
public ?ActionButton $send = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,17 @@

namespace Olcs\Form\Model\Fieldset\Message;

use Common\Form\Element\DynamicSelect;
use Common\Form\Elements\InputFilters\ActionButton;
use Common\Form\Elements\Types\GuidanceTranslated;
use Common\Form\Model\Fieldset\MultipleFileUpload;
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;

class Create
{
/**
* @Form\Options({
* "label": "messaging.subject",
* "empty_option": "Please select",
* "disable_inarray_validator": false,
* "service_name": \Common\Service\Data\MessagingSubject::class
* })
* @Form\Attributes({
* "class": "govuk-select"
* })
* @Form\Type(\Common\Form\Element\DynamicSelect::class)
* @Form\Required(true)
* @Form\Name("inputs")
* @Form\Attributes({"id": "inputs"})
* @Form\ComposedObject(CreateInput::class)
*/
public ?DynamicSelect $messageSubject = null;

/**
* @Form\Options({
* "label": "messaging.app-or-lic-no",
* "empty_option": "Please select",
* "disable_inarray_validator": false,
* "service_name": \Olcs\Service\Data\MessagingAppOrLicNo::class,
* "use_groups": true
* })
* @Form\Attributes({
* "class": "govuk-select"
* })
* @Form\Type(\Common\Form\Element\DynamicSelect::class)
* @Form\Required(true)
*/
public ?DynamicSelect $appOrLicNo = null;

/**
* @Form\Attributes({
* "class": "extra-long",
* "maxlength": 1000
* })
* @Form\Options({
* "label": "",
* "hint": "You can enter up to 1000 characters"
* })
* @Form\Required(true)
* @Form\Type(\Laminas\Form\Element\Textarea::class)
* @Form\Filter(\Laminas\Filter\StringTrim::class)
* @Form\Validator(\Laminas\Validator\StringLength::class, options={"min": 5, "max": 1000})
*/
public ?TextArea $messageContent = null;
public ?CreateInput $inputs = null;

/**
* @Form\Name("file")
Expand All @@ -68,22 +24,9 @@ class Create
public ?MultipleFileUpload $file = null;

/**
* @Form\Attributes({"value": "markup-messaging-new-conversation-timeframe"})
* @Form\Type(\Common\Form\Elements\Types\GuidanceTranslated::class)
*/
public ?GuidanceTranslated $guidance = null;

/**
* @Form\Attributes({
* "type": "submit",
* "data-module": "govuk-button",
* "class": "govuk-button govuk-button--default",
* "id": "send"
* })
* @Form\Options({
* "label": "Send message",
* })
* @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class)
* @Form\Name("actions")
* @Form\Attributes({"id": "actions"})
* @Form\ComposedObject(Actions::class)
*/
public ?ActionButton $create = null;
public ?Actions $send = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Olcs\Form\Model\Fieldset\Message;

use Common\Form\Element\DynamicSelect;
use Common\Service\Data\MessagingSubject;
use Laminas\Filter\StringTrim;
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;
use Laminas\Validator\StringLength;
use Olcs\Service\Data\MessagingAppOrLicNo;

class CreateInput
{
/**
* @Form\Options({
* "label": "messaging.subject",
* "empty_option": "Please select",
* "disable_inarray_validator": false,
* "service_name": MessagingSubject::class
* })
* @Form\Attributes({
* "class": "govuk-select"
* })
* @Form\Type(DynamicSelect::class)
* @Form\Required(true)
*/
public ?DynamicSelect $messageSubject = null;

/**
* @Form\Options({
* "label": "messaging.app-or-lic-no",
* "empty_option": "Please select",
* "disable_inarray_validator": false,
* "service_name": MessagingAppOrLicNo::class,
* "use_groups": true
* })
* @Form\Attributes({
* "class": "govuk-select"
* })
* @Form\Type(DynamicSelect::class)
* @Form\Required(true)
*/
public ?DynamicSelect $appOrLicNo = null;

/**
* @Form\Attributes({
* "class": "extra-long",
* "maxlength": 1000
* })
* @Form\Options({
* "label": "",
* "hint": "You can enter up to 1000 characters"
* })
* @Form\Required(true)
* @Form\Type(Textarea::class)
* @Form\Filter(StringTrim::class)
* @Form\Validator(StringLength::class, options={"min": 5, "max": 1000})
*/
public ?Textarea $messageContent = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,17 @@

namespace Olcs\Form\Model\Fieldset\Message;

use Common\Form\Elements\InputFilters\ActionButton;
use Common\Form\Model\Fieldset\MultipleFileUpload;
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;
use Laminas\Filter\StringTrim;
use Laminas\Validator\StringLength;

class Reply
{
/**
* @Form\Attributes({
* "class": "extra-long",
* "maxlength": 1000
* })
* @Form\Options({
* "label": "",
* "hint": "You can enter up to 1000 characters"
* })
* @Form\Required(true)
* @Form\Type(Textarea::class)
* @Form\Filter(StringTrim::class)
* @Form\Validator(StringLength::class, options={"min": 5, "max": 1000})
* @Form\Name("inputs")
* @Form\Attributes({"id": "inputs"})
* @Form\ComposedObject(ReplyInput::class)
*/
public ?TextArea $reply = null;
public ?ReplyInput $inputs = null;

/**
* @Form\Name("file")
Expand All @@ -37,16 +24,9 @@ class Reply
public ?MultipleFileUpload $file = null;

/**
* @Form\Attributes({
* "type": "submit",
* "data-module": "govuk-button",
* "class": "govuk-button govuk-button--default",
* "id": "send"
* })
* @Form\Options({
* "label": "Send message"
* })
* @Form\Type(ActionButton::class)
* @Form\Name("actions")
* @Form\Attributes({"id": "actions"})
* @Form\ComposedObject(Actions::class)
*/
public ?ActionButton $send = null;
public ?Actions $send = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Olcs\Form\Model\Fieldset\Message;

use Laminas\Filter\StringTrim;
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;
use Laminas\Validator\StringLength;

class ReplyInput
{
/**
* @Form\Attributes({
* "class": "extra-long",
* "maxlength": 1000
* })
* @Form\Options({
* "label": "",
* "hint": "You can enter up to 1000 characters"
* })
* @Form\Required(true)
* @Form\Type(Textarea::class)
* @Form\Filter(StringTrim::class)
* @Form\Validator(StringLength::class, options={"min": 5, "max": 1000})
*/
public ?TextArea $reply = null;
}
Loading

0 comments on commit 6df11f8

Please sign in to comment.