53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\System\Modal;
|
|
|
|
use App\Models\Webhook;
|
|
use App\Services\WebhookService;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class WebhookCreateModal extends ModalComponent
|
|
{
|
|
public string $name = '';
|
|
public string $url = '';
|
|
public array $selected = [];
|
|
public bool $is_active = true;
|
|
|
|
public function save(): void
|
|
{
|
|
$this->validate([
|
|
'name' => 'required|string|max:80',
|
|
'url' => 'required|url|max:500',
|
|
'selected' => 'required|array|min:1',
|
|
'selected.*' => 'in:' . implode(',', array_keys(Webhook::allEvents())),
|
|
], [
|
|
'selected.required' => 'Bitte mindestens ein Event auswählen.',
|
|
'selected.min' => 'Bitte mindestens ein Event auswählen.',
|
|
]);
|
|
|
|
Webhook::create([
|
|
'name' => $this->name,
|
|
'url' => $this->url,
|
|
'events' => $this->selected,
|
|
'secret' => WebhookService::generateSecret(),
|
|
'is_active' => $this->is_active,
|
|
]);
|
|
|
|
$this->dispatch('webhook-saved');
|
|
$this->closeModal();
|
|
}
|
|
|
|
public function toggleAll(): void
|
|
{
|
|
$all = array_keys(Webhook::allEvents());
|
|
$this->selected = count($this->selected) === count($all) ? [] : $all;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.system.modal.webhook-create-modal', [
|
|
'allEvents' => Webhook::allEvents(),
|
|
]);
|
|
}
|
|
}
|