2023-05-25 16:27:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Team;
|
2023-06-14 09:54:00 +00:00
|
|
|
use App\Notifications\Notifications\TestNotification;
|
2023-05-25 16:27:52 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class DiscordSettings extends Component
|
|
|
|
{
|
2023-06-02 10:34:45 +00:00
|
|
|
public Team $model;
|
2023-05-25 16:27:52 +00:00
|
|
|
protected $rules = [
|
2023-06-20 17:08:43 +00:00
|
|
|
'model.discord.enabled' => 'nullable|boolean',
|
|
|
|
'model.discord.webhook_url' => 'required|url',
|
|
|
|
'model.discord_notifications.test' => 'nullable|boolean',
|
|
|
|
'model.discord_notifications.deployments' => 'nullable|boolean',
|
2023-07-26 13:32:46 +00:00
|
|
|
'model.discord_notifications.status_changes' => 'nullable|boolean',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
2023-06-20 17:08:43 +00:00
|
|
|
'model.discord.webhook_url' => 'Discord Webhook',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
2023-06-01 10:15:33 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->submit();
|
|
|
|
} catch (\Exception $e) {
|
2023-06-20 17:08:43 +00:00
|
|
|
$this->model->discord->enabled = false;
|
2023-06-01 11:24:20 +00:00
|
|
|
$this->validate();
|
2023-06-01 10:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-19 13:24:04 +00:00
|
|
|
public function saveModel()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
|
|
|
$this->model->save();
|
2023-06-01 10:15:33 +00:00
|
|
|
if (is_a($this->model, Team::class)) {
|
2023-05-25 16:27:52 +00:00
|
|
|
session(['currentTeam' => $this->model]);
|
|
|
|
}
|
2023-06-19 12:31:42 +00:00
|
|
|
$this->emit('success', 'Settings saved.');
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
2023-06-01 10:15:33 +00:00
|
|
|
public function submit()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-06-01 10:15:33 +00:00
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->validate();
|
|
|
|
$this->saveModel();
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
2023-06-01 10:15:33 +00:00
|
|
|
public function sendTestNotification()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-06-20 13:04:46 +00:00
|
|
|
$this->model->notify(new TestNotification('discord'));
|
|
|
|
$this->emit('success', 'Test notification sent.');
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
|
|
|
}
|