From 5210218a45a24da5c830ca2482b769cd983559d9 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:38:25 +0100 Subject: [PATCH] feat: New Discord notification UI --- app/Livewire/Notifications/Discord.php | 78 +++++++++++++------ .../livewire/notifications/discord.blade.php | 56 +++++++++---- 2 files changed, 94 insertions(+), 40 deletions(-) diff --git a/app/Livewire/Notifications/Discord.php b/app/Livewire/Notifications/Discord.php index 7a177a227..c5ec471d7 100644 --- a/app/Livewire/Notifications/Discord.php +++ b/app/Livewire/Notifications/Discord.php @@ -2,6 +2,7 @@ namespace App\Livewire\Notifications; +use App\Models\DiscordNotificationSettings; use App\Models\Team; use App\Notifications\Test; use Livewire\Attributes\Validate; @@ -11,6 +12,8 @@ class Discord extends Component { public Team $team; + public DiscordNotificationSettings $settings; + #[Validate(['boolean'])] public bool $discordEnabled = false; @@ -18,27 +21,43 @@ class Discord extends Component public ?string $discordWebhookUrl = null; #[Validate(['boolean'])] - public bool $discordNotificationsTest = false; + public bool $deploymentSuccessDiscordNotifications = false; #[Validate(['boolean'])] - public bool $discordNotificationsDeployments = false; + public bool $deploymentFailureDiscordNotifications = true; #[Validate(['boolean'])] - public bool $discordNotificationsStatusChanges = false; + public bool $statusChangeDiscordNotifications = false; #[Validate(['boolean'])] - public bool $discordNotificationsDatabaseBackups = false; + public bool $backupSuccessDiscordNotifications = false; #[Validate(['boolean'])] - public bool $discordNotificationsScheduledTasks = false; + public bool $backupFailureDiscordNotifications = true; #[Validate(['boolean'])] - public bool $discordNotificationsServerDiskUsage = false; + public bool $scheduledTaskSuccessDiscordNotifications = false; + + #[Validate(['boolean'])] + public bool $scheduledTaskFailureDiscordNotifications = true; + + #[Validate(['boolean'])] + public bool $dockerCleanupDiscordNotifications = false; + + #[Validate(['boolean'])] + public bool $serverDiskUsageDiscordNotifications = true; + + #[Validate(['boolean'])] + public bool $serverReachableDiscordNotifications = false; + + #[Validate(['boolean'])] + public bool $serverUnreachableDiscordNotifications = true; public function mount() { try { $this->team = auth()->user()->currentTeam(); + $this->settings = $this->team->discordNotificationSettings; $this->syncData(); } catch (\Throwable $e) { return handleError($e, $this); @@ -49,25 +68,38 @@ class Discord extends Component { if ($toModel) { $this->validate(); - $this->team->discord_enabled = $this->discordEnabled; - $this->team->discord_webhook_url = $this->discordWebhookUrl; - $this->team->discord_notifications_test = $this->discordNotificationsTest; - $this->team->discord_notifications_deployments = $this->discordNotificationsDeployments; - $this->team->discord_notifications_status_changes = $this->discordNotificationsStatusChanges; - $this->team->discord_notifications_database_backups = $this->discordNotificationsDatabaseBackups; - $this->team->discord_notifications_scheduled_tasks = $this->discordNotificationsScheduledTasks; - $this->team->discord_notifications_server_disk_usage = $this->discordNotificationsServerDiskUsage; - $this->team->save(); + $this->settings->discord_enabled = $this->discordEnabled; + $this->settings->discord_webhook_url = $this->discordWebhookUrl; + + $this->settings->deployment_success_discord_notifications = $this->deploymentSuccessDiscordNotifications; + $this->settings->deployment_failure_discord_notifications = $this->deploymentFailureDiscordNotifications; + $this->settings->status_change_discord_notifications = $this->statusChangeDiscordNotifications; + $this->settings->backup_success_discord_notifications = $this->backupSuccessDiscordNotifications; + $this->settings->backup_failure_discord_notifications = $this->backupFailureDiscordNotifications; + $this->settings->scheduled_task_success_discord_notifications = $this->scheduledTaskSuccessDiscordNotifications; + $this->settings->scheduled_task_failure_discord_notifications = $this->scheduledTaskFailureDiscordNotifications; + $this->settings->docker_cleanup_discord_notifications = $this->dockerCleanupDiscordNotifications; + $this->settings->server_disk_usage_discord_notifications = $this->serverDiskUsageDiscordNotifications; + $this->settings->server_reachable_discord_notifications = $this->serverReachableDiscordNotifications; + $this->settings->server_unreachable_discord_notifications = $this->serverUnreachableDiscordNotifications; + + $this->settings->save(); refreshSession(); } else { - $this->discordEnabled = $this->team->discord_enabled; - $this->discordWebhookUrl = $this->team->discord_webhook_url; - $this->discordNotificationsTest = $this->team->discord_notifications_test; - $this->discordNotificationsDeployments = $this->team->discord_notifications_deployments; - $this->discordNotificationsStatusChanges = $this->team->discord_notifications_status_changes; - $this->discordNotificationsDatabaseBackups = $this->team->discord_notifications_database_backups; - $this->discordNotificationsScheduledTasks = $this->team->discord_notifications_scheduled_tasks; - $this->discordNotificationsServerDiskUsage = $this->team->discord_notifications_server_disk_usage; + $this->discordEnabled = $this->settings->discord_enabled; + $this->discordWebhookUrl = $this->settings->discord_webhook_url; + + $this->deploymentSuccessDiscordNotifications = $this->settings->deployment_success_discord_notifications; + $this->deploymentFailureDiscordNotifications = $this->settings->deployment_failure_discord_notifications; + $this->statusChangeDiscordNotifications = $this->settings->status_change_discord_notifications; + $this->backupSuccessDiscordNotifications = $this->settings->backup_success_discord_notifications; + $this->backupFailureDiscordNotifications = $this->settings->backup_failure_discord_notifications; + $this->scheduledTaskSuccessDiscordNotifications = $this->settings->scheduled_task_success_discord_notifications; + $this->scheduledTaskFailureDiscordNotifications = $this->settings->scheduled_task_failure_discord_notifications; + $this->dockerCleanupDiscordNotifications = $this->settings->docker_cleanup_discord_notifications; + $this->serverDiskUsageDiscordNotifications = $this->settings->server_disk_usage_discord_notifications; + $this->serverReachableDiscordNotifications = $this->settings->server_reachable_discord_notifications; + $this->serverUnreachableDiscordNotifications = $this->settings->server_unreachable_discord_notifications; } } diff --git a/resources/views/livewire/notifications/discord.blade.php b/resources/views/livewire/notifications/discord.blade.php index af6f98b0a..0173e8d2e 100644 --- a/resources/views/livewire/notifications/discord.blade.php +++ b/resources/views/livewire/notifications/discord.blade.php @@ -3,7 +3,7 @@ Notifications | Coolify -
+

Discord

@@ -12,7 +12,7 @@ @if ($discordEnabled) - Send Test Notifications + Send Test Notification @endif
@@ -24,20 +24,42 @@ id="discordWebhookUrl" label="Webhook" />
@if ($discordEnabled) -

Subscribe to events

-
- @if (isDev()) - - @endif - - - - - -
+

Notification Settings

+

+ Select events for which you would like to receive Discord notifications. +

+
+
+

Deployments

+
+ + + +
+
+
+

Backups

+
+ + +
+
+
+

Scheduled Tasks

+
+ + +
+
+
+

Server

+
+ + + + +
+
+
@endif