From c7f1e3b4965d2274cf69838455dabfbb2f76e0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Fri, 14 Jun 2024 15:30:52 +0200 Subject: [PATCH] Add some user friendlyness to the peak wms dashboard inside the admin panel --- src/Controller/Admin/PeakWMSController.php | 11 ++++++ src/Resources/config/services/client.xml | 6 ++-- src/Resources/config/services/controller.xml | 1 + .../views/admin/peak_wms/index.html.twig | 35 +++++++++++++------ 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Controller/Admin/PeakWMSController.php b/src/Controller/Admin/PeakWMSController.php index f43dd2f..a3a66b9 100644 --- a/src/Controller/Admin/PeakWMSController.php +++ b/src/Controller/Admin/PeakWMSController.php @@ -4,6 +4,7 @@ namespace Setono\SyliusPeakWMSPlugin\Controller\Admin; +use Setono\PeakWMS\Client\ClientInterface; use Setono\SyliusPeakWMSPlugin\Message\Command\RegisterWebhooks; use Setono\SyliusPeakWMSPlugin\Registrar\WebhookRegistrarInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -16,12 +17,22 @@ final class PeakWMSController extends AbstractController public function __construct( private readonly MessageBusInterface $commandBus, private readonly WebhookRegistrarInterface $webhookRegistrar, + private readonly ClientInterface $client, ) { } public function index(): Response { + $apiError = false; + + try { + $this->client->ping(); + } catch (\Throwable) { + $apiError = 'There was an error connecting to the API. Please check your credentials and try again. If you continue to experience issues, did you forget to enable/disable the sandbox?'; + } + return $this->render('@SetonoSyliusPeakWMSPlugin/admin/peak_wms/index.html.twig', [ + 'apiError' => $apiError, 'webhooksShouldBeRegistered' => $this->webhookRegistrar->outOfDate(), ]); } diff --git a/src/Resources/config/services/client.xml b/src/Resources/config/services/client.xml index b91a820..2ba0a44 100644 --- a/src/Resources/config/services/client.xml +++ b/src/Resources/config/services/client.xml @@ -2,13 +2,15 @@ - + %setono_sylius_peak_wms.api_key% + + %kernel.debug% + diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index ff51798..4593721 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -6,6 +6,7 @@ class="Setono\SyliusPeakWMSPlugin\Controller\Admin\PeakWMSController" public="true"> + diff --git a/src/Resources/views/admin/peak_wms/index.html.twig b/src/Resources/views/admin/peak_wms/index.html.twig index 4e0fe5b..01bba9a 100644 --- a/src/Resources/views/admin/peak_wms/index.html.twig +++ b/src/Resources/views/admin/peak_wms/index.html.twig @@ -13,18 +13,31 @@ -
-
-
-

{{ 'setono_sylius_peak_wms.ui.webhooks'|trans }}

+ {% if apiError %} +
+
+
+
+
There was an error connecting to the API
+

{{ apiError }}

+
+
+
+
+ {% else %} +
+
+
+

{{ 'setono_sylius_peak_wms.ui.webhooks'|trans }}

- {% if webhooksShouldBeRegistered %} -

{{ 'setono_sylius_peak_wms.ui.register_webhooks_information'|trans }}

- {% endif %} - - {{ 'setono_sylius_peak_wms.ui.register_webhooks'|trans }} - + {% if webhooksShouldBeRegistered %} +

{{ 'setono_sylius_peak_wms.ui.register_webhooks_information'|trans }}

+ {% endif %} + + {{ 'setono_sylius_peak_wms.ui.register_webhooks'|trans }} + +
-
+ {% endif %} {% endblock %}