From 019670d5d1aded184905ad770b7462e95d383cac Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 15 Sep 2023 11:28:44 +0200 Subject: [PATCH] fix: smtp view --- .../Notifications/DiscordSettings.php | 3 - .../Livewire/Notifications/EmailSettings.php | 6 +- .../Notifications/TelegramSettings.php | 3 - app/Http/Livewire/Team/Form.php | 1 - app/Models/Team.php | 7 ++ bootstrap/helpers/shared.php | 6 +- .../notifications/email-settings.blade.php | 98 +++++++++---------- 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/app/Http/Livewire/Notifications/DiscordSettings.php b/app/Http/Livewire/Notifications/DiscordSettings.php index 97a8878f1..800addc24 100644 --- a/app/Http/Livewire/Notifications/DiscordSettings.php +++ b/app/Http/Livewire/Notifications/DiscordSettings.php @@ -46,9 +46,6 @@ class DiscordSettings extends Component public function saveModel() { $this->team->save(); - if (is_a($this->team, Team::class)) { - refreshSession(); - } $this->emit('success', 'Settings saved.'); } diff --git a/app/Http/Livewire/Notifications/EmailSettings.php b/app/Http/Livewire/Notifications/EmailSettings.php index 939b8bce0..5bbf846f4 100644 --- a/app/Http/Livewire/Notifications/EmailSettings.php +++ b/app/Http/Livewire/Notifications/EmailSettings.php @@ -110,9 +110,6 @@ class EmailSettings extends Component public function saveModel() { $this->team->save(); - if (is_a($this->team, Team::class)) { - refreshSession(); - } $this->emit('success', 'Settings saved.'); } public function submit() @@ -141,10 +138,11 @@ class EmailSettings extends Component try { $this->resetErrorBag(); $this->validate([ + 'team.smtp_from_address' => 'required|email', + 'team.smtp_from_name' => 'required', 'team.resend_api_key' => 'required' ]); $this->team->save(); - refreshSession(); $this->emit('success', 'Settings saved successfully.'); } catch (\Throwable $e) { $this->team->resend_enabled = false; diff --git a/app/Http/Livewire/Notifications/TelegramSettings.php b/app/Http/Livewire/Notifications/TelegramSettings.php index 15dca1490..b0313e1fb 100644 --- a/app/Http/Livewire/Notifications/TelegramSettings.php +++ b/app/Http/Livewire/Notifications/TelegramSettings.php @@ -52,9 +52,6 @@ class TelegramSettings extends Component public function saveModel() { $this->team->save(); - if (is_a($this->team, Team::class)) { - refreshSession(); - } $this->emit('success', 'Settings saved.'); } diff --git a/app/Http/Livewire/Team/Form.php b/app/Http/Livewire/Team/Form.php index 212957e44..febbf33a3 100644 --- a/app/Http/Livewire/Team/Form.php +++ b/app/Http/Livewire/Team/Form.php @@ -27,7 +27,6 @@ class Form extends Component $this->validate(); try { $this->team->save(); - refreshSession(); } catch (\Throwable $e) { return general_error_handler($e, $this); } diff --git a/app/Models/Team.php b/app/Models/Team.php index 558c8dc3b..e090796d5 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -19,6 +19,13 @@ class Team extends Model implements SendsDiscord, SendsEmail 'resend_api_key' => 'encrypted', ]; + protected static function booted() + { + static::saved(function () { + refreshSession(); + }); + } + public function routeNotificationForDiscord() { return data_get($this, 'discord_webhook_url', null); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index ffd429c58..39066e1b6 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -62,7 +62,11 @@ function showBoarding(): bool function refreshSession(?Team $team = null): void { if (!$team) { - $team = User::find(auth()->user()->id)->teams->first(); + if (auth()->user()->currentTeam()) { + $team = Team::find(auth()->user()->currentTeam()->id); + } else { + $team = User::find(auth()->user()->id)->teams->first(); + } } Cache::forget('team:' . auth()->user()->id); Cache::remember('team:' . auth()->user()->id, 3600, function() use ($team) { diff --git a/resources/views/livewire/notifications/email-settings.blade.php b/resources/views/livewire/notifications/email-settings.blade.php index d7acaac1a..d96eb4875 100644 --- a/resources/views/livewire/notifications/email-settings.blade.php +++ b/resources/views/livewire/notifications/email-settings.blade.php @@ -21,7 +21,8 @@ Copy from Instance Settings @endif - @if (isEmailEnabled($team) && auth()->user()->isAdminFromSession()) + @if (isEmailEnabled($team) && + auth()->user()->isAdminFromSession()) Send Test Email @@ -51,61 +52,52 @@
-
- -
SMTP Server
-
- -
-
-
-
-
-
- - - -
-
- - - -
-
-
- - Save - -
-
+
+

SMTP Server

+
+
-
-
- -
Resend
-
- +
+
+
+ + + +
+
+ + + +
-
-
- -
-
- -
-
-
- - Save - -
- +
+ + Save + +
+ +
+
+

Resend

+
+
-
+
+
+
+ +
+
+
+ + Save + +
+
+
@endif @if (isEmailEnabled($team) || data_get($team, 'use_instance_email_settings'))