From 8a11de9b1a8b7cbfdd9ec60cbd419c1cb22ca88c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sat, 15 Mar 2025 22:26:59 +0100 Subject: [PATCH] fix(core): improve instantSave logic and error handling --- app/Livewire/SettingsEmail.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Livewire/SettingsEmail.php b/app/Livewire/SettingsEmail.php index 15e68306f..4205594a5 100644 --- a/app/Livewire/SettingsEmail.php +++ b/app/Livewire/SettingsEmail.php @@ -114,19 +114,24 @@ class SettingsEmail extends Component public function instantSave(string $type) { try { + $currentSmtpEnabled = $this->settings->smtp_enabled; + $currentResendEnabled = $this->settings->resend_enabled; $this->resetErrorBag(); if ($type === 'SMTP') { $this->submitSmtp(); + $this->resendEnabled = $this->settings->resend_enabled = false; } elseif ($type === 'Resend') { $this->submitResend(); + $this->smtpEnabled = $this->settings->smtp_enabled = false; } + $this->settings->save(); } catch (\Throwable $e) { if ($type === 'SMTP') { - $this->smtpEnabled = false; + $this->smtpEnabled = $currentSmtpEnabled; } elseif ($type === 'Resend') { - $this->resendEnabled = false; + $this->resendEnabled = $currentResendEnabled; } return handleError($e, $this); @@ -156,9 +161,6 @@ class SettingsEmail extends Component 'smtpEncryption.required' => 'Encryption type is required.', ]); - $this->resendEnabled = false; - $this->settings->resend_enabled = false; - $this->settings->smtp_enabled = $this->smtpEnabled; $this->settings->smtp_host = $this->smtpHost; $this->settings->smtp_port = $this->smtpPort; @@ -194,9 +196,6 @@ class SettingsEmail extends Component 'smtpFromName.required' => 'From Name is required.', ]); - $this->smtpEnabled = false; - $this->settings->smtp_enabled = false; - $this->settings->resend_enabled = $this->resendEnabled; $this->settings->resend_api_key = $this->resendApiKey; $this->settings->smtp_from_address = $this->smtpFromAddress;