generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from mailcarrierapp/feat/users-dashboard
[2.x] Users management dashboard
- Loading branch information
Showing
6 changed files
with
154 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace MailCarrier\Resources; | ||
|
||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Stringable; | ||
use MailCarrier\Enums\Auth; | ||
use MailCarrier\Models\User; | ||
use MailCarrier\Resources\UserResource\Pages; | ||
|
||
class UserResource extends Resource | ||
{ | ||
protected static ?string $model = User::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-users'; | ||
|
||
protected static ?string $navigationGroup = 'Management'; | ||
|
||
/** | ||
* List all the records. | ||
*/ | ||
public static function table(Tables\Table $table): Tables\Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->placeholder('No name provided'), | ||
|
||
Tables\Columns\TextColumn::make('email') | ||
->formatStateUsing( | ||
fn (string $state) => Str::of($state) | ||
->when( | ||
Str::of($state)->before('@')->length() > 5, | ||
fn (Stringable $str) => $str->mask('*', 3, strpos($state, '@') - 3), | ||
fn (Stringable $str) => $str->mask('*', 0, strpos($state, '@')), | ||
) | ||
), | ||
|
||
Tables\Columns\TextColumn::make('created_at') | ||
->label('Creation date') | ||
->dateTime(), | ||
]) | ||
->actions([ | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->query(User::query()->whereNot('email', Auth::AuthManagerEmail->value)); | ||
} | ||
|
||
/** | ||
* Get Filament CRUD pages. | ||
*/ | ||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListUsers::route('/'), | ||
]; | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace MailCarrier\Resources\UserResource\Actions; | ||
|
||
use Filament\Actions\CreateAction as BaseCreateAction; | ||
use Filament\Forms; | ||
use Filament\Support\Enums\Alignment; | ||
use Filament\Support\Enums\MaxWidth; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\HtmlString; | ||
use MailCarrier\Facades\MailCarrier; | ||
use MailCarrier\Models\User; | ||
use MailCarrier\Resources\UserResource; | ||
|
||
class CreateAction extends BaseCreateAction | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->authorize(fn (): bool => UserResource::canCreate()); | ||
|
||
$this->modalFooterActionsAlignment(Alignment::End); | ||
$this->modalWidth(MaxWidth::Large); | ||
|
||
if (!is_null(MailCarrier::getSocialAuthDriver())) { | ||
$this->form([ | ||
Forms\Components\Placeholder::make('cannot_create_users') | ||
->label('') | ||
->content(new HtmlString(<<<'HTML' | ||
<div class="bg-warning-100 dark:bg-warning-500/20 border border-warning-300 dark:border-warning-600 rounded py-2 px-4"> | ||
Cannot create users with social authentication enabled. | ||
</div> | ||
HTML)), | ||
]); | ||
|
||
$this->modalHeading('Cannot create users'); | ||
$this->modalIcon('heroicon-o-exclamation-triangle'); | ||
$this->modalIconColor('warning'); | ||
$this->modalSubmitAction(false); | ||
$this->modalCancelActionLabel('Close'); | ||
$this->extraModalFooterActions([]); | ||
|
||
return; | ||
} | ||
|
||
$this->form([ | ||
Forms\Components\TextInput::make('name') | ||
->required(), | ||
|
||
Forms\Components\TextInput::make('email') | ||
->email() | ||
->required() | ||
->unique((new User())->getTable(), 'email'), | ||
|
||
Forms\Components\TextInput::make('password') | ||
->password() | ||
->revealable() | ||
->required(), | ||
]); | ||
|
||
$this->mutateFormDataUsing(function (array $data): array { | ||
$data['password'] = Hash::make($data['password']); | ||
|
||
return $data; | ||
}); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace MailCarrier\Resources\UserResource\Pages; | ||
|
||
use Filament\Resources\Pages\ListRecords; | ||
use MailCarrier\Resources\UserResource; | ||
use MailCarrier\Resources\UserResource\Actions\CreateAction; | ||
|
||
class ListUsers extends ListRecords | ||
{ | ||
protected static string $resource = UserResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
CreateAction::make(), | ||
]; | ||
} | ||
} |