fix: missing monitor alert
This commit is contained in:
@@ -7,19 +7,18 @@ use App\Monitor\Action\Handler\AddMonitorHandler;
|
|||||||
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
||||||
use App\Monitor\Action\Input\AddMonitorInput;
|
use App\Monitor\Action\Input\AddMonitorInput;
|
||||||
use App\Monitor\Action\Input\DeleteMonitorInput;
|
use App\Monitor\Action\Input\DeleteMonitorInput;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
use Symfony\Component\Mercure\Update;
|
use Symfony\Component\Mercure\Update;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
class ApiController extends AbstractController
|
class ApiController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'twig')]
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly Environment $renderer,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
||||||
@@ -32,14 +31,10 @@ class ApiController extends AbstractController
|
|||||||
$command->userId = $this->getUser()->getId();
|
$command->userId = $this->getUser()->getId();
|
||||||
$response = $handler->handle($command);
|
$response = $handler->handle($command);
|
||||||
|
|
||||||
$hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
'alerts',
|
title: 'Success',
|
||||||
$this->renderer->render('broadcast/Alert.stream.html.twig', [
|
message: "New monitor added for {$input->title}",
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => "New monitor added for {$input->title}",
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
|
|||||||
@@ -82,4 +82,10 @@
|
|||||||
|
|
||||||
{% block remove %}
|
{% block remove %}
|
||||||
<turbo-stream action="remove" target="monitor_{{ id }}"></turbo-stream>
|
<turbo-stream action="remove" target="monitor_{{ id }}"></turbo-stream>
|
||||||
|
|
||||||
|
<turbo-stream action="prepend" target="alert_list">
|
||||||
|
<template>
|
||||||
|
<twig:Alert title="Success" message="Your Monitor for '{{ entity.title }}' has been removed." alert_id="monitor_alert_{{ entity.id }}" data-controller="alert" />
|
||||||
|
</template>
|
||||||
|
</turbo-stream>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user