team = auth()->user()->currentTeam(); $this->settings = $this->team->slackNotificationSettings; $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); } } public function syncData(bool $toModel = false) { if ($toModel) { $this->validate(); $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->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; } } public function instantSaveSlackEnabled() { try { $this->validate([ 'slackWebhookUrl' => 'required', ], [ 'slackWebhookUrl.required' => 'Slack Webhook URL is required.', ]); $this->saveModel(); } catch (\Throwable $e) { $this->slackEnabled = false; return handleError($e, $this); } } public function instantSave() { try { $this->syncData(true); } catch (\Throwable $e) { return handleError($e, $this); } } public function submit() { try { $this->resetErrorBag(); $this->syncData(true); $this->saveModel(); } catch (\Throwable $e) { return handleError($e, $this); } } public function saveModel() { $this->syncData(true); refreshSession(); $this->dispatch('success', 'Settings saved.'); } public function sendTestNotification() { try { $this->team->notify(new Test); $this->dispatch('success', 'Test notification sent.'); } catch (\Throwable $e) { return handleError($e, $this); } } public function render() { return view('livewire.notifications.slack'); } }