Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Test email 500 Error #4352

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/Livewire/Notifications/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Email extends Component
#[Validate(['nullable', 'string'])]
public ?string $resendApiKey = null;

#[Validate(['required', 'email'])]
public string $testEmailAddress = '';

public function mount()
{
try {
Expand Down Expand Up @@ -132,14 +135,21 @@ public function syncData(bool $toModel = false)
}
}

public function sendTestNotification()
public function sendTestEmail()
{
try {
$this->validate([
'testEmailAddress' => 'required|email',
], [
'testEmailAddress.required' => 'Test email address is required.',
'testEmailAddress.email' => 'Please enter a valid email address.',
]);

$executed = RateLimiter::attempt(
'test-email:'.$this->team->id,
$perMinute = 0,
function () {
$this->team?->notify(new Test($this->emails));
$this->team?->notify(new Test($this->testEmailAddress));
$this->dispatch('success', 'Test Email sent.');
},
$decaySeconds = 10,
Expand Down
6 changes: 3 additions & 3 deletions resources/views/livewire/notifications/email.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@endif
@if (isEmailEnabled($team) && auth()->user()->isAdminFromSession() && isTestEmailEnabled($team))
<x-modal-input buttonTitle="Send Test Email" title="Send Test Email">
<form wire:submit='submit' class="flex flex-col w-full gap-2">
<x-forms.input placeholder="[email protected]" id="emails" label="Recipients" required />
<x-forms.button wire:click="sendTestNotification" @click="modalOpen=false">
<form wire:submit.prevent="sendTestEmail" class="flex flex-col w-full gap-2">
<x-forms.input wire:model="testEmailAddress" placeholder="[email protected]" id="testEmailAddress" label="Recipients" required />
<x-forms.button type="submit" @click="modalOpen=false">
Send Email
</x-forms.button>
</form>
Expand Down