fix: smtp view

This commit is contained in:
Andras Bacsai
2023-09-15 11:28:44 +02:00
parent b07cc500e7
commit 019670d5d1
7 changed files with 59 additions and 65 deletions

View File

@@ -46,9 +46,6 @@ class DiscordSettings extends Component
public function saveModel() public function saveModel()
{ {
$this->team->save(); $this->team->save();
if (is_a($this->team, Team::class)) {
refreshSession();
}
$this->emit('success', 'Settings saved.'); $this->emit('success', 'Settings saved.');
} }

View File

@@ -110,9 +110,6 @@ class EmailSettings extends Component
public function saveModel() public function saveModel()
{ {
$this->team->save(); $this->team->save();
if (is_a($this->team, Team::class)) {
refreshSession();
}
$this->emit('success', 'Settings saved.'); $this->emit('success', 'Settings saved.');
} }
public function submit() public function submit()
@@ -141,10 +138,11 @@ class EmailSettings extends Component
try { try {
$this->resetErrorBag(); $this->resetErrorBag();
$this->validate([ $this->validate([
'team.smtp_from_address' => 'required|email',
'team.smtp_from_name' => 'required',
'team.resend_api_key' => 'required' 'team.resend_api_key' => 'required'
]); ]);
$this->team->save(); $this->team->save();
refreshSession();
$this->emit('success', 'Settings saved successfully.'); $this->emit('success', 'Settings saved successfully.');
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->team->resend_enabled = false; $this->team->resend_enabled = false;

View File

@@ -52,9 +52,6 @@ class TelegramSettings extends Component
public function saveModel() public function saveModel()
{ {
$this->team->save(); $this->team->save();
if (is_a($this->team, Team::class)) {
refreshSession();
}
$this->emit('success', 'Settings saved.'); $this->emit('success', 'Settings saved.');
} }

View File

@@ -27,7 +27,6 @@ class Form extends Component
$this->validate(); $this->validate();
try { try {
$this->team->save(); $this->team->save();
refreshSession();
} catch (\Throwable $e) { } catch (\Throwable $e) {
return general_error_handler($e, $this); return general_error_handler($e, $this);
} }

View File

@@ -19,6 +19,13 @@ class Team extends Model implements SendsDiscord, SendsEmail
'resend_api_key' => 'encrypted', 'resend_api_key' => 'encrypted',
]; ];
protected static function booted()
{
static::saved(function () {
refreshSession();
});
}
public function routeNotificationForDiscord() public function routeNotificationForDiscord()
{ {
return data_get($this, 'discord_webhook_url', null); return data_get($this, 'discord_webhook_url', null);

View File

@@ -62,8 +62,12 @@ function showBoarding(): bool
function refreshSession(?Team $team = null): void function refreshSession(?Team $team = null): void
{ {
if (!$team) { if (!$team) {
if (auth()->user()->currentTeam()) {
$team = Team::find(auth()->user()->currentTeam()->id);
} else {
$team = User::find(auth()->user()->id)->teams->first(); $team = User::find(auth()->user()->id)->teams->first();
} }
}
Cache::forget('team:' . auth()->user()->id); Cache::forget('team:' . auth()->user()->id);
Cache::remember('team:' . auth()->user()->id, 3600, function() use ($team) { Cache::remember('team:' . auth()->user()->id, 3600, function() use ($team) {
return $team; return $team;

View File

@@ -21,7 +21,8 @@
Copy from Instance Settings Copy from Instance Settings
</x-forms.button> </x-forms.button>
@endif @endif
@if (isEmailEnabled($team) && auth()->user()->isAdminFromSession()) @if (isEmailEnabled($team) &&
auth()->user()->isAdminFromSession())
<x-forms.button onclick="sendTestEmail.showModal()" <x-forms.button onclick="sendTestEmail.showModal()"
class="text-white normal-case btn btn-xs no-animation btn-primary"> class="text-white normal-case btn btn-xs no-animation btn-primary">
Send Test Email Send Test Email
@@ -51,19 +52,15 @@
</x-forms.button> </x-forms.button>
</form> </form>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<details class="border rounded collapse border-coolgray-500 collapse-arrow "> <div class="p-4 border border-coolgray-500">
<summary class="text-xl collapse-title"> <h3>SMTP Server</h3>
<div>SMTP Server</div>
<div class="w-32"> <div class="w-32">
<x-forms.checkbox instantSave id="team.smtp_enabled" label="Enabled" /> <x-forms.checkbox instantSave id="team.smtp_enabled" label="Enabled" />
</div> </div>
</summary>
<div class="collapse-content">
<form wire:submit.prevent='submit' class="flex flex-col"> <form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row"> <div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input required id="team.smtp_host" placeholder="smtp.mailgun.org" <x-forms.input required id="team.smtp_host" placeholder="smtp.mailgun.org" label="Host" />
label="Host" />
<x-forms.input required id="team.smtp_port" placeholder="587" label="Port" /> <x-forms.input required id="team.smtp_port" placeholder="587" label="Port" />
<x-forms.input id="team.smtp_encryption" helper="If SMTP uses SSL, set it to 'tls'." <x-forms.input id="team.smtp_encryption" helper="If SMTP uses SSL, set it to 'tls'."
placeholder="tls" label="Encryption" /> placeholder="tls" label="Encryption" />
@@ -82,15 +79,11 @@
</div> </div>
</form> </form>
</div> </div>
</details> <div class="p-4 border border-coolgray-500">
<details class="border rounded collapse border-coolgray-500 collapse-arrow"> <h3>Resend</h3>
<summary class="text-xl collapse-title">
<div>Resend</div>
<div class="w-32"> <div class="w-32">
<x-forms.checkbox instantSave='instantSaveResend' id="team.resend_enabled" label="Enabled" /> <x-forms.checkbox instantSave='instantSaveResend' id="team.resend_enabled" label="Enabled" />
</div> </div>
</summary>
<div class="collapse-content">
<form wire:submit.prevent='submitResend' class="flex flex-col"> <form wire:submit.prevent='submitResend' class="flex flex-col">
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row"> <div class="flex flex-col w-full gap-2 xl:flex-row">
@@ -105,7 +98,6 @@
</div> </div>
</form> </form>
</div> </div>
</details>
</div> </div>
@endif @endif
@if (isEmailEnabled($team) || data_get($team, 'use_instance_email_settings')) @if (isEmailEnabled($team) || data_get($team, 'use_instance_email_settings'))