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 @@ public function submit()
public function saveModel()
{
$this->team->save();
if (is_a($this->team, Team::class)) {
refreshSession();
}
$this->emit('success', 'Settings saved.');
}

View File

@ -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;

View File

@ -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.');
}

View File

@ -27,7 +27,6 @@ public function submit()
$this->validate();
try {
$this->team->save();
refreshSession();
} catch (\Throwable $e) {
return general_error_handler($e, $this);
}

View File

@ -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);

View File

@ -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) {

View File

@ -21,7 +21,8 @@
Copy from Instance Settings
</x-forms.button>
@endif
@if (isEmailEnabled($team) && auth()->user()->isAdminFromSession())
@if (isEmailEnabled($team) &&
auth()->user()->isAdminFromSession())
<x-forms.button onclick="sendTestEmail.showModal()"
class="text-white normal-case btn btn-xs no-animation btn-primary">
Send Test Email
@ -51,61 +52,52 @@ class="text-white normal-case btn btn-xs no-animation btn-primary">
</x-forms.button>
</form>
<div class="flex flex-col gap-4">
<details class="border rounded collapse border-coolgray-500 collapse-arrow ">
<summary class="text-xl collapse-title">
<div>SMTP Server</div>
<div class="w-32">
<x-forms.checkbox instantSave id="team.smtp_enabled" label="Enabled" />
</div>
</summary>
<div class="collapse-content">
<form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input required id="team.smtp_host" placeholder="smtp.mailgun.org"
label="Host" />
<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'."
placeholder="tls" label="Encryption" />
</div>
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input id="team.smtp_username" label="SMTP Username" />
<x-forms.input id="team.smtp_password" type="password" label="SMTP Password" />
<x-forms.input id="team.smtp_timeout" helper="Timeout value for sending emails."
label="Timeout" />
</div>
</div>
<div class="flex justify-end gap-4 pt-6">
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
</form>
<div class="p-4 border border-coolgray-500">
<h3>SMTP Server</h3>
<div class="w-32">
<x-forms.checkbox instantSave id="team.smtp_enabled" label="Enabled" />
</div>
</details>
<details class="border rounded collapse border-coolgray-500 collapse-arrow">
<summary class="text-xl collapse-title">
<div>Resend</div>
<div class="w-32">
<x-forms.checkbox instantSave='instantSaveResend' id="team.resend_enabled" label="Enabled" />
<form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input required id="team.smtp_host" placeholder="smtp.mailgun.org" label="Host" />
<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'."
placeholder="tls" label="Encryption" />
</div>
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input id="team.smtp_username" label="SMTP Username" />
<x-forms.input id="team.smtp_password" type="password" label="SMTP Password" />
<x-forms.input id="team.smtp_timeout" helper="Timeout value for sending emails."
label="Timeout" />
</div>
</div>
</summary>
<div class="collapse-content">
<form wire:submit.prevent='submitResend' class="flex flex-col">
<div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input required type="password" id="team.resend_api_key" placeholder="API key"
label="API Key" />
</div>
</div>
<div class="flex justify-end gap-4 pt-6">
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
</form>
<div class="flex justify-end gap-4 pt-6">
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
</form>
</div>
<div class="p-4 border border-coolgray-500">
<h3>Resend</h3>
<div class="w-32">
<x-forms.checkbox instantSave='instantSaveResend' id="team.resend_enabled" label="Enabled" />
</div>
</details>
<form wire:submit.prevent='submitResend' class="flex flex-col">
<div class="flex flex-col gap-4">
<div class="flex flex-col w-full gap-2 xl:flex-row">
<x-forms.input required type="password" id="team.resend_api_key" placeholder="API key"
label="API Key" />
</div>
</div>
<div class="flex justify-end gap-4 pt-6">
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
</form>
</div>
</div>
@endif
@if (isEmailEnabled($team) || data_get($team, 'use_instance_email_settings'))