diff --git a/app/Livewire/Notifications/Slack.php b/app/Livewire/Notifications/Slack.php index edd32a071..7fa881641 100644 --- a/app/Livewire/Notifications/Slack.php +++ b/app/Livewire/Notifications/Slack.php @@ -2,6 +2,7 @@ namespace App\Livewire\Notifications; +use App\Models\SlackNotificationSettings; use App\Models\Team; use App\Notifications\Test; use Livewire\Attributes\Validate; @@ -11,6 +12,8 @@ class Slack extends Component { public Team $team; + public SlackNotificationSettings $settings; + #[Validate(['boolean'])] public bool $slackEnabled = false; @@ -18,27 +21,43 @@ class Slack extends Component public ?string $slackWebhookUrl = null; #[Validate(['boolean'])] - public bool $slackNotificationsTest = false; + public bool $deploymentSuccessSlackNotifications = false; #[Validate(['boolean'])] - public bool $slackNotificationsDeployments = false; + public bool $deploymentFailureSlackNotifications = true; #[Validate(['boolean'])] - public bool $slackNotificationsStatusChanges = false; + public bool $statusChangeSlackNotifications = false; #[Validate(['boolean'])] - public bool $slackNotificationsDatabaseBackups = false; + public bool $backupSuccessSlackNotifications = false; #[Validate(['boolean'])] - public bool $slackNotificationsScheduledTasks = false; + public bool $backupFailureSlackNotifications = true; #[Validate(['boolean'])] - public bool $slackNotificationsServerDiskUsage = false; + public bool $scheduledTaskSuccessSlackNotifications = false; + + #[Validate(['boolean'])] + public bool $scheduledTaskFailureSlackNotifications = true; + + #[Validate(['boolean'])] + public bool $dockerCleanupSlackNotifications = false; + + #[Validate(['boolean'])] + public bool $serverDiskUsageSlackNotifications = true; + + #[Validate(['boolean'])] + public bool $serverReachableSlackNotifications = false; + + #[Validate(['boolean'])] + public bool $serverUnreachableSlackNotifications = true; public function mount() { try { $this->team = auth()->user()->currentTeam(); + $this->settings = $this->team->slackNotificationSettings; $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); @@ -49,25 +68,38 @@ class Slack extends Component { if ($toModel) { $this->validate(); - $this->team->slack_enabled = $this->slackEnabled; - $this->team->slack_webhook_url = $this->slackWebhookUrl; - $this->team->slack_notifications_test = $this->slackNotificationsTest; - $this->team->slack_notifications_deployments = $this->slackNotificationsDeployments; - $this->team->slack_notifications_status_changes = $this->slackNotificationsStatusChanges; - $this->team->slack_notifications_database_backups = $this->slackNotificationsDatabaseBackups; - $this->team->slack_notifications_scheduled_tasks = $this->slackNotificationsScheduledTasks; - $this->team->slack_notifications_server_disk_usage = $this->slackNotificationsServerDiskUsage; - $this->team->save(); + $this->settings->slack_enabled = $this->slackEnabled; + $this->settings->slack_webhook_url = $this->slackWebhookUrl; + + $this->settings->deployment_success_slack_notifications = $this->deploymentSuccessSlackNotifications; + $this->settings->deployment_failure_slack_notifications = $this->deploymentFailureSlackNotifications; + $this->settings->status_change_slack_notifications = $this->statusChangeSlackNotifications; + $this->settings->backup_success_slack_notifications = $this->backupSuccessSlackNotifications; + $this->settings->backup_failure_slack_notifications = $this->backupFailureSlackNotifications; + $this->settings->scheduled_task_success_slack_notifications = $this->scheduledTaskSuccessSlackNotifications; + $this->settings->scheduled_task_failure_slack_notifications = $this->scheduledTaskFailureSlackNotifications; + $this->settings->docker_cleanup_slack_notifications = $this->dockerCleanupSlackNotifications; + $this->settings->server_disk_usage_slack_notifications = $this->serverDiskUsageSlackNotifications; + $this->settings->server_reachable_slack_notifications = $this->serverReachableSlackNotifications; + $this->settings->server_unreachable_slack_notifications = $this->serverUnreachableSlackNotifications; + + $this->settings->save(); refreshSession(); } else { - $this->slackEnabled = $this->team->slack_enabled; - $this->slackWebhookUrl = $this->team->slack_webhook_url; - $this->slackNotificationsTest = $this->team->slack_notifications_test; - $this->slackNotificationsDeployments = $this->team->slack_notifications_deployments; - $this->slackNotificationsStatusChanges = $this->team->slack_notifications_status_changes; - $this->slackNotificationsDatabaseBackups = $this->team->slack_notifications_database_backups; - $this->slackNotificationsScheduledTasks = $this->team->slack_notifications_scheduled_tasks; - $this->slackNotificationsServerDiskUsage = $this->team->slack_notifications_server_disk_usage; + $this->slackEnabled = $this->settings->slack_enabled; + $this->slackWebhookUrl = $this->settings->slack_webhook_url; + + $this->deploymentSuccessSlackNotifications = $this->settings->deployment_success_slack_notifications; + $this->deploymentFailureSlackNotifications = $this->settings->deployment_failure_slack_notifications; + $this->statusChangeSlackNotifications = $this->settings->status_change_slack_notifications; + $this->backupSuccessSlackNotifications = $this->settings->backup_success_slack_notifications; + $this->backupFailureSlackNotifications = $this->settings->backup_failure_slack_notifications; + $this->scheduledTaskSuccessSlackNotifications = $this->settings->scheduled_task_success_slack_notifications; + $this->scheduledTaskFailureSlackNotifications = $this->settings->scheduled_task_failure_slack_notifications; + $this->dockerCleanupSlackNotifications = $this->settings->docker_cleanup_slack_notifications; + $this->serverDiskUsageSlackNotifications = $this->settings->server_disk_usage_slack_notifications; + $this->serverReachableSlackNotifications = $this->settings->server_reachable_slack_notifications; + $this->serverUnreachableSlackNotifications = $this->settings->server_unreachable_slack_notifications; } } @@ -82,6 +114,7 @@ class Slack extends Component $this->saveModel(); } catch (\Throwable $e) { $this->slackEnabled = false; + return handleError($e, $this); } } @@ -127,4 +160,4 @@ class Slack extends Component { return view('livewire.notifications.slack'); } -} \ No newline at end of file +} diff --git a/resources/views/livewire/notifications/slack.blade.php b/resources/views/livewire/notifications/slack.blade.php index b3685173c..052581837 100644 --- a/resources/views/livewire/notifications/slack.blade.php +++ b/resources/views/livewire/notifications/slack.blade.php @@ -1,43 +1,65 @@