coolify/app/Http/Livewire/Notifications/DiscordSettings.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2023-05-25 18:27:52 +02:00
<?php
namespace App\Http\Livewire\Notifications;
use App\Models\Team;
2023-07-28 10:55:26 +02:00
use App\Notifications\Test;
2023-05-25 18:27:52 +02:00
use Livewire\Component;
class DiscordSettings extends Component
{
2023-09-06 14:31:38 +02:00
public Team $team;
2023-05-25 18:27:52 +02:00
protected $rules = [
2023-09-06 14:31:38 +02:00
'team.discord_enabled' => 'nullable|boolean',
'team.discord_webhook_url' => 'required|url',
'team.discord_notifications_test' => 'nullable|boolean',
'team.discord_notifications_deployments' => 'nullable|boolean',
'team.discord_notifications_status_changes' => 'nullable|boolean',
'team.discord_notifications_database_backups' => 'nullable|boolean',
2023-05-25 18:27:52 +02:00
];
protected $validationAttributes = [
2023-09-06 14:31:38 +02:00
'team.discord_webhook_url' => 'Discord Webhook',
2023-05-25 18:27:52 +02:00
];
2023-09-06 14:31:38 +02:00
public function mount()
{
$this->team = auth()->user()->currentTeam();
}
2023-06-01 12:15:33 +02:00
public function instantSave()
{
try {
$this->submit();
} catch (\Exception $e) {
ray($e->getMessage());
2023-09-06 14:31:38 +02:00
$this->team->discord_enabled = false;
2023-06-01 13:24:20 +02:00
$this->validate();
2023-06-01 12:15:33 +02:00
}
}
public function submit()
{
$this->resetErrorBag();
$this->validate();
$this->saveModel();
}
2023-06-19 15:24:04 +02:00
public function saveModel()
2023-05-25 18:27:52 +02:00
{
2023-09-06 14:31:38 +02:00
$this->team->save();
if (is_a($this->team, Team::class)) {
2023-08-22 17:44:49 +02:00
refreshSession();
2023-05-25 18:27:52 +02:00
}
2023-06-19 14:31:42 +02:00
$this->emit('success', 'Settings saved.');
2023-05-25 18:27:52 +02:00
}
2023-06-01 12:15:33 +02:00
public function sendTestNotification()
2023-05-25 18:27:52 +02:00
{
2023-09-06 14:31:38 +02:00
$this->team->notify(new Test());
2023-06-20 15:04:46 +02:00
$this->emit('success', 'Test notification sent.');
2023-05-25 18:27:52 +02:00
}
}