|
4 | 4 |
|
5 | 5 | namespace App\Filament\Resources;
|
6 | 6 |
|
| 7 | +use App\Actions\User\BanUserAction; |
| 8 | +use App\Actions\User\UnBanUserAction; |
7 | 9 | use App\Filament\Resources\UserResource\Pages;
|
8 | 10 | use App\Models\User;
|
9 | 11 | use Awcodes\FilamentBadgeableColumn\Components\Badge;
|
10 | 12 | use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn;
|
| 13 | +use Filament\Forms\Components\TextInput; |
| 14 | +use Filament\Notifications\Notification; |
11 | 15 | use Filament\Resources\Resource;
|
12 | 16 | use Filament\Tables;
|
13 | 17 | use Filament\Tables\Table;
|
@@ -51,21 +55,63 @@ public static function table(Table $table): Table
|
51 | 55 | ->icon('untitledui-inbox')
|
52 | 56 | ->description(fn ($record): ?string => $record->phone_number),
|
53 | 57 | Tables\Columns\TextColumn::make('email_verified_at')
|
54 |
| - ->label('Validation Email') |
| 58 | + ->label(__('user.validate_email')) |
55 | 59 | ->placeholder('N/A')
|
56 | 60 | ->date(),
|
57 | 61 | Tables\Columns\TextColumn::make(name: 'created_at')
|
58 |
| - ->label('Inscription') |
| 62 | + ->label(__('use.inscription')) |
59 | 63 | ->date(),
|
60 | 64 | ])
|
61 | 65 | ->filters([
|
62 | 66 | Tables\Filters\TernaryFilter::make('email_verified_at')
|
63 |
| - ->label('Email Vérifiée') |
| 67 | + ->label(__('user.email_verified')) |
64 | 68 | ->nullable(),
|
65 | 69 | ])
|
66 | 70 | ->actions([
|
67 |
| - Tables\Actions\DeleteAction::make() |
68 |
| - ->iconButton(), |
| 71 | + Tables\Actions\Action::make('ban') |
| 72 | + ->label(__('actions.ban')) |
| 73 | + ->icon('untitledui-archive') |
| 74 | + ->color('warning') |
| 75 | + ->visible(fn ($record) => $record->banned_at == null) |
| 76 | + ->modalHeading(__('user.ban.heading')) |
| 77 | + ->modalDescription(__('user.ban.description')) |
| 78 | + ->authorize('ban', User::class) |
| 79 | + ->form([ |
| 80 | + TextInput::make('banned_reason') |
| 81 | + ->label(__('user.ban.reason')) |
| 82 | + ->required(), |
| 83 | + ]) |
| 84 | + ->action(function (User $record, array $data): void { |
| 85 | + app(BanUserAction::class)->execute($record, $data['banned_reason']); |
| 86 | + |
| 87 | + Notification::make() |
| 88 | + ->success() |
| 89 | + ->duration(5000) |
| 90 | + ->title(__('notifications.user.banned_title')) |
| 91 | + ->body(__('notifications.user.banned_body')) |
| 92 | + ->send(); |
| 93 | + }) |
| 94 | + ->requiresConfirmation(), |
| 95 | + |
| 96 | + Tables\Actions\Action::make('unban') |
| 97 | + ->label(__('actions.unban')) |
| 98 | + ->icon('heroicon-o-check-circle') |
| 99 | + ->color('success') |
| 100 | + ->visible(fn ($record) => $record->banned_at !== null) |
| 101 | + ->authorize('unban', User::class) |
| 102 | + ->action(function (User $record): void { |
| 103 | + app(UnBanUserAction::class)->execute($record); |
| 104 | + |
| 105 | + Notification::make() |
| 106 | + ->success() |
| 107 | + ->title(__('notifications.user.unbanned_title')) |
| 108 | + ->duration(5000) |
| 109 | + ->body(__('notifications.user.unbanned_body')) |
| 110 | + ->send(); |
| 111 | + }) |
| 112 | + ->requiresConfirmation(), |
| 113 | + |
| 114 | + Tables\Actions\DeleteAction::make(), |
69 | 115 | ])
|
70 | 116 | ->bulkActions([
|
71 | 117 | Tables\Actions\DeleteBulkAction::make(),
|
|
0 commit comments