Skip to content

Commit

Permalink
Add some user friendlyness to the peak wms dashboard inside the admin…
Browse files Browse the repository at this point in the history
… panel
  • Loading branch information
loevgaard committed Jun 14, 2024
1 parent 4c7a80d commit c7f1e3b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/Controller/Admin/PeakWMSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Resources/config/services/client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="setono_sylius_peak_wms.client"
class="Setono\PeakWMS\Client\Client">
<service id="setono_sylius_peak_wms.client" class="Setono\PeakWMS\Client\Client">
<argument>%setono_sylius_peak_wms.api_key%</argument>

<call method="setLogger">
<argument type="service" id="logger"/>
</call>
<call method="useSandbox">
<argument>%kernel.debug%</argument>
</call>
</service>
</services>
</container>
1 change: 1 addition & 0 deletions src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class="Setono\SyliusPeakWMSPlugin\Controller\Admin\PeakWMSController" public="true">
<argument type="service" id="setono_sylius_peak_wms.command_bus"/>
<argument type="service" id="setono_sylius_peak_wms.registrar.webhook"/>
<argument type="service" id="setono_sylius_peak_wms.client"/>

<call method="setContainer">
<argument type="service" id="service_container"/>
Expand Down
35 changes: 24 additions & 11 deletions src/Resources/views/admin/peak_wms/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,31 @@

<div class="ui hidden divider"></div>

<div class="ui grid">
<div class="eight wide column">
<div class="ui segment">
<h4 class="ui header">{{ 'setono_sylius_peak_wms.ui.webhooks'|trans }}</h4>
{% if apiError %}
<div class="ui grid">
<div class="eight wide column">
<div class="ui segment">
<div class="ui negative message">
<div class="header">There was an error connecting to the API</div>
<p>{{ apiError }}</p>
</div>
</div>
</div>
</div>
{% else %}
<div class="ui grid">
<div class="eight wide column">
<div class="ui segment">
<h4 class="ui header">{{ 'setono_sylius_peak_wms.ui.webhooks'|trans }}</h4>

{% if webhooksShouldBeRegistered %}
<p>{{ 'setono_sylius_peak_wms.ui.register_webhooks_information'|trans }}</p>
{% endif %}
<a href="{{ path('setono_sylius_peak_wms_admin_peak_wms_register_webhooks') }}" class="ui primary button">
{{ 'setono_sylius_peak_wms.ui.register_webhooks'|trans }}
</a>
{% if webhooksShouldBeRegistered %}
<p>{{ 'setono_sylius_peak_wms.ui.register_webhooks_information'|trans }}</p>
{% endif %}
<a href="{{ path('setono_sylius_peak_wms_admin_peak_wms_register_webhooks') }}" class="ui primary button">
{{ 'setono_sylius_peak_wms.ui.register_webhooks'|trans }}
</a>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}

0 comments on commit c7f1e3b

Please sign in to comment.