a lot hehe

This commit is contained in:
Andras Bacsai
2023-06-01 12:15:33 +02:00
parent c8f70a4e3b
commit 0aa816b4f2
42 changed files with 570 additions and 249 deletions

View File

@@ -4,7 +4,7 @@ namespace App\Http\Livewire\Notifications;
use App\Models\Server;
use App\Models\Team;
use App\Notifications\DemoNotification;
use App\Notifications\TestNotification;
use Illuminate\Support\Facades\Notification;
use Livewire\Component;
@@ -13,31 +13,40 @@ class DiscordSettings extends Component
public Team|Server $model;
protected $rules = [
'model.extra_attributes.discord_webhook' => 'nullable|url',
'model.extra_attributes.discord_active' => 'nullable|boolean',
'model.smtp_attributes.discord_active' => 'nullable|boolean',
'model.smtp_attributes.discord_webhook' => 'required|url',
];
protected $validationAttributes = [
'model.extra_attributes.discord_webhook' => 'Discord Webhook',
'model.smtp_attributes.discord_webhook' => 'Discord Webhook',
];
public function mount($model)
{
//
}
public function instantSave()
{
try {
$this->submit();
} catch (\Exception $e) {
$this->model->smtp_attributes->discord_active = false;
$this->addError('model.smtp_attributes.discord_webhook', $e->getMessage());
}
}
private function saveModel()
{
$this->model->save();
if (is_a($this->model, Team::class)) {
session(['currentTeam' => $this->model]);
}
}
public function submit()
{
$this->resetErrorBag();
$this->validate();
$this->model->save();
if ( is_a($this->model, Team::class)) {
session(['currentTeam' => $this->model]);
}
$this->saveModel();
}
public function sendTestNotification()
{
Notification::send($this->model, new DemoNotification);
}
public function render()
{
return view('livewire.notifications.discord-settings');
Notification::send($this->model, new TestNotification);
}
}