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 @@ public function submit()
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 @@ public function instantSave()
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 @@ public function submitResend()
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 @@ public function submit()
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 @@ public function submit()
$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())