This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Close Conversation Front-end (#13)
* feat: Close Conversation popup (no confirm yet) * feat: Call BE to close conversation * fix: Close button disabled on conversation isClosed * fix: FQCN for form access in controller * fix: Sneaky whitespace somehow * fix: Annotation tidy up for forms * fix: Cancel button is a link in the popup
- Loading branch information
Showing
10 changed files
with
317 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
module/Olcs/src/Controller/Factory/Messages/LicenceCloseConversationControllerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Controller\Factory\Messages; | ||
|
||
use Common\Service\Helper\FlashMessengerHelperService; | ||
use Common\Service\Helper\FormHelperService; | ||
use Common\Service\Helper\TranslationHelperService; | ||
use Common\Service\Script\ScriptFactory; | ||
use Common\Service\Table\TableFactory; | ||
use Laminas\Navigation\Navigation; | ||
use Interop\Container\ContainerInterface; | ||
use Laminas\ServiceManager\FactoryInterface; | ||
use Laminas\ServiceManager\ServiceLocatorInterface; | ||
use Laminas\View\HelperPluginManager; | ||
use Olcs\Controller\Messages\LicenceCloseConversationController; | ||
use Olcs\Controller\Messages\LicenceNewConversationController; | ||
use Olcs\Controller\TaskController; | ||
use Olcs\Service\Data\SubCategory; | ||
use Olcs\Service\Data\UserListInternalExcludingLimitedReadOnlyUsers; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
|
||
class LicenceCloseConversationControllerFactory implements FactoryInterface | ||
{ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
string $requestedName, | ||
?array $options = null | ||
): LicenceCloseConversationController | ||
{ | ||
$container = method_exists($container, 'getServiceLocator') ? $container->getServiceLocator() : $container; | ||
|
||
$scriptFactory = $container->get(ScriptFactory::class); | ||
$formHelper = $container->get(FormHelperService::class); | ||
$tableFactory = $container->get(TableFactory::class); | ||
$viewHelperManager = $container->get(HelperPluginManager::class); | ||
$flashMessengerHelperService = $container->get(FlashMessengerHelperService::class); | ||
|
||
return new LicenceCloseConversationController( | ||
$scriptFactory, | ||
$formHelper, | ||
$tableFactory, | ||
$viewHelperManager, | ||
$flashMessengerHelperService, | ||
); | ||
} | ||
|
||
public function createService(ServiceLocatorInterface $serviceLocator): LicenceCloseConversationController | ||
{ | ||
return $this->__invoke($serviceLocator, LicenceCloseConversationController::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
module/Olcs/src/Controller/Messages/LicenceCloseConversationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Controller\Messages; | ||
|
||
use Common\Controller\Interfaces\ToggleAwareInterface; | ||
use Common\FeatureToggle; | ||
use Common\Service\Helper\FlashMessengerHelperService; | ||
use Common\Service\Helper\FormHelperService; | ||
use Common\Service\Script\ScriptFactory; | ||
use Common\Service\Table\TableFactory; | ||
use Dvsa\Olcs\Transfer\Command\Messaging\Close; | ||
use Laminas\Http\Response; | ||
use Laminas\View\HelperPluginManager; | ||
use Laminas\View\Model\ViewModel; | ||
use Olcs\Controller\AbstractController; | ||
use Olcs\Data\Mapper\Task; | ||
use Olcs\Form\Model\Form\CloseConversation; | ||
|
||
class LicenceCloseConversationController extends AbstractController implements ToggleAwareInterface | ||
{ | ||
protected array $toggleConfig = [ | ||
'default' => [FeatureToggle::MESSAGING], | ||
]; | ||
private FlashMessengerHelperService $flashMessengerHelperService; | ||
|
||
public function __construct( | ||
ScriptFactory $scriptFactory, | ||
FormHelperService $formHelper, | ||
TableFactory $tableFactory, | ||
HelperPluginManager $viewHelperManager, | ||
FlashMessengerHelperService $flashMessengerHelperService | ||
) | ||
{ | ||
parent::__construct($scriptFactory, $formHelper, $tableFactory, $viewHelperManager); | ||
|
||
$this->flashMessengerHelperService = $flashMessengerHelperService; | ||
} | ||
|
||
/** | ||
* @return ViewModel|Response | ||
*/ | ||
public function confirmAction() | ||
{ | ||
$form = $this->getForm(CloseConversation::class); | ||
$form->get('id')->setValue($this->params()->fromRoute('conversation')); | ||
|
||
if ($this->getRequest()->isPost()) { | ||
$closeCommand = Close::create(['id' => $this->params()->fromRoute('conversation')]); | ||
$response = $this->handleCommand($closeCommand); | ||
|
||
if ($response->isOk()) { | ||
$this->flashMessengerHelperService->addSuccessMessage('conversation-closed-success'); | ||
|
||
$params = [ | ||
'licence' => $this->params()->fromRoute('licence'), | ||
'action' => 'close', | ||
]; | ||
return $this->redirect()->toRouteAjax('licence/conversation', $params); | ||
} else if ($response->isClientError()) { | ||
Task::mapFormErrors($response->getResult()['messages'], $form, $this->flashMessengerHelperService); | ||
} else { | ||
$this->flashMessengerHelperService->addUnknownError(); | ||
} | ||
} | ||
|
||
$view = new ViewModel(['form' => $form]); | ||
$view->setTemplate('pages/form'); | ||
|
||
return $this->renderView($view, 'End Conversation'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
module/Olcs/src/Form/Model/Fieldset/CloseConversationActions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Form\Model\Fieldset; | ||
|
||
use Laminas\Form\Annotation as Form; | ||
|
||
/** | ||
* @codeCoverageIgnore No methods | ||
* @Form\Name("main") | ||
* @Form\Attributes({"class": "govuk-button-group"}) | ||
*/ | ||
class CloseConversationActions | ||
{ | ||
/** | ||
* @Form\Attributes({ | ||
* "type": "submit", | ||
* "data-module": "govuk-button", | ||
* "class": "govuk-button govuk-button--warning", | ||
* "id": "close" | ||
* }) | ||
* @Form\Options({ | ||
* "label": "End and archive conversation" | ||
* }) | ||
* @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class) | ||
*/ | ||
public ?ActionButton $close = null; | ||
|
||
/** | ||
* @Form\Attributes({ | ||
* "data-module": "govuk-button", | ||
* "type": "cancel", | ||
* "class": "govuk-link action-button-link", | ||
* "id": "cancel" | ||
* }) | ||
* @Form\Options({ | ||
* "label": "Cancel" | ||
* }) | ||
* @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class) | ||
*/ | ||
public ?ActionButton $cancel = null; | ||
} |
21 changes: 21 additions & 0 deletions
21
module/Olcs/src/Form/Model/Fieldset/CloseConversationText.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olcs\Form\Model\Fieldset; | ||
|
||
use Laminas\Form\Annotation as Form; | ||
|
||
/** | ||
* @Form\Name("main") | ||
*/ | ||
class CloseConversationText | ||
{ | ||
/** | ||
* @Form\Type(\Common\Form\Elements\Types\PlainText::class) | ||
* @Form\Attributes({ | ||
* "value": "The conversation will be removed from the Inbox and a transcript will be archived in docs and attachments tab." | ||
* }) | ||
*/ | ||
public ?PlainText $text = null; | ||
} |
Oops, something went wrong.