team = auth()->user()->currentTeam(); $this->settings = $this->team->webhookNotificationSettings; $this->authorize('view', $this->settings); $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); } } public function syncData(bool $toModel = false) { if ($toModel) { $this->validate(); $this->authorize('update', $this->settings); $this->settings->webhook_enabled = $this->webhookEnabled; $this->settings->webhook_url = $this->webhookUrl; $this->settings->deployment_success_webhook_notifications = $this->deploymentSuccessWebhookNotifications; $this->settings->deployment_failure_webhook_notifications = $this->deploymentFailureWebhookNotifications; $this->settings->status_change_webhook_notifications = $this->statusChangeWebhookNotifications; $this->settings->backup_success_webhook_notifications = $this->backupSuccessWebhookNotifications; $this->settings->backup_failure_webhook_notifications = $this->backupFailureWebhookNotifications; $this->settings->scheduled_task_success_webhook_notifications = $this->scheduledTaskSuccessWebhookNotifications; $this->settings->scheduled_task_failure_webhook_notifications = $this->scheduledTaskFailureWebhookNotifications; $this->settings->docker_cleanup_success_webhook_notifications = $this->dockerCleanupSuccessWebhookNotifications; $this->settings->docker_cleanup_failure_webhook_notifications = $this->dockerCleanupFailureWebhookNotifications; $this->settings->server_disk_usage_webhook_notifications = $this->serverDiskUsageWebhookNotifications; $this->settings->server_reachable_webhook_notifications = $this->serverReachableWebhookNotifications; $this->settings->server_unreachable_webhook_notifications = $this->serverUnreachableWebhookNotifications; $this->settings->server_patch_webhook_notifications = $this->serverPatchWebhookNotifications; $this->settings->save(); refreshSession(); } else { $this->webhookEnabled = $this->settings->webhook_enabled; $this->webhookUrl = $this->settings->webhook_url; $this->deploymentSuccessWebhookNotifications = $this->settings->deployment_success_webhook_notifications; $this->deploymentFailureWebhookNotifications = $this->settings->deployment_failure_webhook_notifications; $this->statusChangeWebhookNotifications = $this->settings->status_change_webhook_notifications; $this->backupSuccessWebhookNotifications = $this->settings->backup_success_webhook_notifications; $this->backupFailureWebhookNotifications = $this->settings->backup_failure_webhook_notifications; $this->scheduledTaskSuccessWebhookNotifications = $this->settings->scheduled_task_success_webhook_notifications; $this->scheduledTaskFailureWebhookNotifications = $this->settings->scheduled_task_failure_webhook_notifications; $this->dockerCleanupSuccessWebhookNotifications = $this->settings->docker_cleanup_success_webhook_notifications; $this->dockerCleanupFailureWebhookNotifications = $this->settings->docker_cleanup_failure_webhook_notifications; $this->serverDiskUsageWebhookNotifications = $this->settings->server_disk_usage_webhook_notifications; $this->serverReachableWebhookNotifications = $this->settings->server_reachable_webhook_notifications; $this->serverUnreachableWebhookNotifications = $this->settings->server_unreachable_webhook_notifications; $this->serverPatchWebhookNotifications = $this->settings->server_patch_webhook_notifications; } } public function instantSaveWebhookEnabled() { try { $original = $this->webhookEnabled; $this->validate([ 'webhookUrl' => 'required', ], [ 'webhookUrl.required' => 'Webhook URL is required.', ]); $this->saveModel(); } catch (\Throwable $e) { $this->webhookEnabled = $original; 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(); if (isDev()) { ray('Webhook settings saved', [ 'webhook_enabled' => $this->settings->webhook_enabled, 'webhook_url' => $this->settings->webhook_url, ]); } $this->dispatch('success', 'Settings saved.'); } public function sendTestNotification() { try { $this->authorize('sendTest', $this->settings); if (isDev()) { ray('Sending test webhook notification', [ 'team_id' => $this->team->id, 'webhook_url' => $this->settings->webhook_url, ]); } $this->team->notify(new Test(channel: 'webhook')); $this->dispatch('success', 'Test notification sent.'); } catch (\Throwable $e) { return handleError($e, $this); } } public function render() { return view('livewire.notifications.webhook'); } }