2023-05-25 16:27:52 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Notifications;
|
2023-05-25 16:27:52 +00:00
|
|
|
|
|
|
|
use App\Models\Team;
|
2023-07-28 08:55:26 +00:00
|
|
|
use App\Notifications\Test;
|
2023-05-25 16:27:52 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
2024-03-22 12:25:43 +00:00
|
|
|
class Discord extends Component
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-09-06 12:31:38 +00:00
|
|
|
public Team $team;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-05-25 16:27:52 +00:00
|
|
|
protected $rules = [
|
2023-09-06 12:31:38 +00: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',
|
2024-05-21 13:36:26 +00:00
|
|
|
'team.discord_notifications_scheduled_tasks' => 'nullable|boolean',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-05-25 16:27:52 +00:00
|
|
|
protected $validationAttributes = [
|
2023-09-06 12:31:38 +00:00
|
|
|
'team.discord_webhook_url' => 'Discord Webhook',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-06 12:31:38 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->team = auth()->user()->currentTeam();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-01 10:15:33 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->submit();
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-07-27 19:26:15 +00:00
|
|
|
ray($e->getMessage());
|
2023-09-06 12:31:38 +00:00
|
|
|
$this->team->discord_enabled = false;
|
2023-06-01 11:24:20 +00:00
|
|
|
$this->validate();
|
2023-06-01 10:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->validate();
|
|
|
|
$this->saveModel();
|
|
|
|
}
|
|
|
|
|
2023-06-19 13:24:04 +00:00
|
|
|
public function saveModel()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-09-06 12:31:38 +00:00
|
|
|
$this->team->save();
|
2023-09-15 15:30:26 +00:00
|
|
|
refreshSession();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Settings saved.');
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-01 10:15:33 +00:00
|
|
|
public function sendTestNotification()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-12-13 11:01:27 +00:00
|
|
|
$this->team?->notify(new Test());
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Test notification sent.');
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-22 12:25:43 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.notifications.discord');
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|