-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement statuses on organisations (#169)
* implement statuses on organisations * resend invitation action * change status from guest to invited * wip --------- Co-authored-by: Andrei Ioniță <[email protected]>
- Loading branch information
1 parent
4b4228f
commit 3bb9305
Showing
11 changed files
with
181 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/Filament/Resources/OrganisationResource/Actions/ResendInvitationAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'resend_invitation'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->color('secondary'); | ||
|
||
$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(); | ||
$this->success(); | ||
}); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->label(__('organisation.action.resend_invitation.button')); | ||
|
||
$this->modalHeading(__('organisation.action.resend_invitation.heading')); | ||
$this->modalSubheading(__('organisation.action.resend_invitation.subheading')); | ||
$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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.