Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Apr 8, 2024
1 parent 707b413 commit 1f5e11d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace App\Filament\Resources\OrganisationResource\Actions;

use App\Models\Organisation;
use Filament\Notifications\Notification;
use Filament\Pages\Actions\Action;
use Illuminate\Support\Facades\RateLimiter;

class ResendInvitationAction extends Action
{
Expand All @@ -20,9 +22,18 @@ protected function setUp(): void

$this->color('secondary');

$this->action(function (Organisation $record, Action $action) {
$this->action(function (Organisation $record) {
$key = $this->getRateLimiterKey($record);
$maxAttempts = 1;

if (RateLimiter::tooManyAttempts($key, $maxAttempts)) {
return $this->failure();
}

RateLimiter::increment($key, 3600); // 1h

$record->users->first()->sendWelcomeNotification();
$action->success();
$this->success();
});

$this->requiresConfirmation();
Expand All @@ -34,5 +45,17 @@ protected function setUp(): void
$this->modalButton(__('organisation.action.resend_invitation.button'));

$this->successNotificationTitle(__('organisation.action.resend_invitation.success'));

$this->failureNotification(
fn (Notification $notification) => $notification
->danger()
->title(__('organisation.action.resend_invitation.failure_title'))
->body(__('organisation.action.resend_invitation.failure_body'))
);
}

private function getRateLimiterKey(Organisation $organisation): string
{
return 'resend-invitation:' . $organisation->id;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sentry/sentry-laravel": "^4.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.9",
"barryvdh/laravel-debugbar": "^3.13",
"barryvdh/laravel-ide-helper": "^2.13",
"fakerphp/faker": "^1.23",
"friendsofphp/php-cs-fixer": "^3.39",
Expand Down
70 changes: 37 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lang/ro/organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
'heading' => 'Retrimite invitație',
'subheading' => 'Ești sigur că vrei să retrimit invitația?',
'success' => 'Invitația a fost retimisă.',
'failure_title' => 'Invitația nu a putut fi trimisă.',
'failure_body' => 'Acestei organizații i-a fost retrimisă invitația recent. Te rugăm să mai încerci peste o oră.',
],
],

Expand Down

0 comments on commit 1f5e11d

Please sign in to comment.