fix: use Livewire refresh method and lock properties

This commit is contained in:
peaklabs-dev
2024-12-11 19:34:44 +01:00
parent 866abfb1d4
commit 48ddc65435
4 changed files with 33 additions and 5 deletions

View File

@@ -14,8 +14,10 @@ class Email extends Component
{ {
protected $listeners = ['refresh' => '$refresh']; protected $listeners = ['refresh' => '$refresh'];
#[Locked]
public Team $team; public Team $team;
#[Locked]
public EmailNotificationSettings $settings; public EmailNotificationSettings $settings;
#[Locked] #[Locked]

View File

@@ -5,22 +5,27 @@ namespace App\Livewire\Notifications;
use App\Models\PushoverNotificationSettings; use App\Models\PushoverNotificationSettings;
use App\Models\Team; use App\Models\Team;
use App\Notifications\Test; use App\Notifications\Test;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
class Pushover extends Component class Pushover extends Component
{ {
protected $listeners = ['refresh' => '$refresh'];
#[Locked]
public Team $team; public Team $team;
#[Locked]
public PushoverNotificationSettings $settings; public PushoverNotificationSettings $settings;
#[Validate(['boolean'])] #[Validate(['boolean'])]
public bool $pushoverEnabled = false; public bool $pushoverEnabled = false;
#[Validate(['string', 'nullable'])] #[Validate(['nullable', 'string'])]
public ?string $pushoverUserKey = null; public ?string $pushoverUserKey = null;
#[Validate(['string', 'nullable'])] #[Validate(['nullable', 'string'])]
public ?string $pushoverApiToken = null; public ?string $pushoverApiToken = null;
#[Validate(['boolean'])] #[Validate(['boolean'])]
@@ -75,7 +80,7 @@ class Pushover extends Component
if ($toModel) { if ($toModel) {
$this->validate(); $this->validate();
$this->settings->pushover_enabled = $this->pushoverEnabled; $this->settings->pushover_enabled = $this->pushoverEnabled;
$this->settings->pushover_user_key_key = $this->pushoverUserKey; $this->settings->pushover_user_key = $this->pushoverUserKey;
$this->settings->pushover_api_token = $this->pushoverApiToken; $this->settings->pushover_api_token = $this->pushoverApiToken;
$this->settings->deployment_success_pushover_notifications = $this->deploymentSuccessPushoverNotifications; $this->settings->deployment_success_pushover_notifications = $this->deploymentSuccessPushoverNotifications;
@@ -95,7 +100,7 @@ class Pushover extends Component
refreshSession(); refreshSession();
} else { } else {
$this->pushoverEnabled = $this->settings->pushover_enabled; $this->pushoverEnabled = $this->settings->pushover_enabled;
$this->pushoverUserKey = $this->settings->pushover_user_key_key; $this->pushoverUserKey = $this->settings->pushover_user_key;
$this->pushoverApiToken = $this->settings->pushover_api_token; $this->pushoverApiToken = $this->settings->pushover_api_token;
$this->deploymentSuccessPushoverNotifications = $this->settings->deployment_success_pushover_notifications; $this->deploymentSuccessPushoverNotifications = $this->settings->deployment_success_pushover_notifications;
@@ -128,6 +133,8 @@ class Pushover extends Component
$this->pushoverEnabled = false; $this->pushoverEnabled = false;
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }
@@ -137,6 +144,8 @@ class Pushover extends Component
$this->syncData(true); $this->syncData(true);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }

View File

@@ -5,13 +5,18 @@ namespace App\Livewire\Notifications;
use App\Models\SlackNotificationSettings; use App\Models\SlackNotificationSettings;
use App\Models\Team; use App\Models\Team;
use App\Notifications\Test; use App\Notifications\Test;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
class Slack extends Component class Slack extends Component
{ {
protected $listeners = ['refresh' => '$refresh'];
#[Locked]
public Team $team; public Team $team;
#[Locked]
public SlackNotificationSettings $settings; public SlackNotificationSettings $settings;
#[Validate(['boolean'])] #[Validate(['boolean'])]
@@ -121,6 +126,8 @@ class Slack extends Component
$this->slackEnabled = false; $this->slackEnabled = false;
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }
@@ -130,6 +137,8 @@ class Slack extends Component
$this->syncData(true); $this->syncData(true);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }

View File

@@ -5,13 +5,18 @@ namespace App\Livewire\Notifications;
use App\Models\Team; use App\Models\Team;
use App\Models\TelegramNotificationSettings; use App\Models\TelegramNotificationSettings;
use App\Notifications\Test; use App\Notifications\Test;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
class Telegram extends Component class Telegram extends Component
{ {
protected $listeners = ['refresh' => '$refresh'];
#[Locked]
public Team $team; public Team $team;
#[Locked]
public TelegramNotificationSettings $settings; public TelegramNotificationSettings $settings;
#[Validate(['boolean'])] #[Validate(['boolean'])]
@@ -141,7 +146,6 @@ class Telegram extends Component
$this->settings->telegram_notifications_server_unreachable_topic_id = $this->telegramNotificationsServerUnreachableTopicId; $this->settings->telegram_notifications_server_unreachable_topic_id = $this->telegramNotificationsServerUnreachableTopicId;
$this->settings->save(); $this->settings->save();
refreshSession();
} else { } else {
$this->telegramEnabled = $this->settings->telegram_enabled; $this->telegramEnabled = $this->settings->telegram_enabled;
$this->telegramToken = $this->settings->telegram_token; $this->telegramToken = $this->settings->telegram_token;
@@ -181,6 +185,8 @@ class Telegram extends Component
$this->syncData(true); $this->syncData(true);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }
@@ -210,6 +216,8 @@ class Telegram extends Component
$this->telegramEnabled = false; $this->telegramEnabled = false;
return handleError($e, $this); return handleError($e, $this);
} finally {
$this->dispatch('refresh');
} }
} }