-
-
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.
Merge branch 'main' into documents-tests
- Loading branch information
Showing
21 changed files
with
728 additions
and
215 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
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
64 changes: 64 additions & 0 deletions
64
app/Filament/Resources/VolunteerResource/Actions/ExportVolunteersExample.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\VolunteerResource\Actions; | ||
|
||
use App\Models\Volunteer; | ||
use pxlrbt\FilamentExcel\Actions\Pages\ExportAction; | ||
use pxlrbt\FilamentExcel\Columns\Column; | ||
use pxlrbt\FilamentExcel\Exports\ExcelExport; | ||
|
||
class ExportVolunteersExample extends ExportAction | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->label(__('volunteer.labels.download_example')); | ||
|
||
$this->exports([ | ||
ExcelExport::make() | ||
->withColumns([ | ||
Column::make('first_name'), | ||
Column::make('last_name'), | ||
Column::make('email'), | ||
Column::make('phone'), | ||
Column::make('cnp'), | ||
Column::make('rol'), | ||
Column::make('specialisations'), | ||
Column::make('has_first_aid_accreditation'), | ||
Column::make('county') | ||
->formatStateUsing(fn ($state) => $state->name), | ||
Column::make('city') | ||
->formatStateUsing(fn ($state) => $state->name), | ||
]), | ||
]); | ||
} | ||
|
||
public function handleExport(array $data) | ||
{ | ||
$examples = Volunteer::factory() | ||
->count(10) | ||
->make() | ||
->each(function ($item) { | ||
$item->load('county'); | ||
$item->load('city'); | ||
|
||
return $item; | ||
}); | ||
|
||
$examplesArray = []; | ||
foreach ($examples as $example) { | ||
$examplesArray[] = $example; | ||
} | ||
|
||
$exportable = $this->getSelectedExport($data); | ||
$livewire = $this->getLivewire(); | ||
|
||
return app()->call([$exportable, 'hydrate'], [ | ||
'livewire' => $this->getLivewire(), | ||
'records' => $examples, | ||
'formData' => data_get($data, $exportable->getName()), | ||
])->export(); | ||
} | ||
} |
Oops, something went wrong.