Skip to content

Commit

Permalink
Merge pull request #4352 from peaklabs-dev/fix-test-email
Browse files Browse the repository at this point in the history
Fix: Test email 500 Error
  • Loading branch information
andrasbacsai authored Nov 22, 2024
2 parents 8b16afb + 81f8371 commit 75b7a32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit 75b7a32

Please sign in to comment.