|
4 | 4 |
|
5 | 5 | namespace App\Filament\Resources; |
6 | 6 |
|
7 | | -use App\Filament\Actions\ApprovedAction; |
8 | | -use App\Filament\Actions\DeclinedAction; |
9 | 7 | use App\Filament\Resources\ArticleResource\Pages; |
10 | 8 | use App\Models\Article; |
11 | 9 | use Filament\Resources\Resource; |
12 | 10 | use Filament\Tables; |
| 11 | +use Filament\Tables\Actions\Action; |
13 | 12 | use Filament\Tables\Actions\ActionGroup; |
| 13 | +use Filament\Tables\Actions\BulkAction; |
14 | 14 | use Filament\Tables\Columns\TextColumn; |
15 | 15 | use Filament\Tables\Filters\Filter; |
16 | 16 | use Filament\Tables\Table; |
17 | 17 | use Illuminate\Database\Eloquent\Builder; |
| 18 | +use Illuminate\Database\Eloquent\Collection; |
18 | 19 |
|
19 | 20 | final class ArticleResource extends Resource |
20 | 21 | { |
@@ -63,14 +64,62 @@ public static function table(Table $table): Table |
63 | 64 |
|
64 | 65 | ->actions([ |
65 | 66 | ActionGroup::make([ |
66 | | - ApprovedAction::make('approved'), |
67 | | - DeclinedAction::make('declined'), |
| 67 | + Action::make('approved') |
| 68 | + ->label('Approuver') |
| 69 | + ->icon('heroicon-s-check') |
| 70 | + ->color('success') |
| 71 | + ->modalHeading(__('Voulez vous approuver cet article')) |
| 72 | + ->successNotificationTitle(__('Opération effectuée avec succès')) |
| 73 | + ->requiresConfirmation() |
| 74 | + ->modalIcon('heroicon-s-check') |
| 75 | + ->action(function ($record): void { |
| 76 | + $record->approved_at = now(); |
| 77 | + $record->declined_at = null; |
| 78 | + $record->save(); |
| 79 | + }), |
| 80 | + Action::make('declined') |
| 81 | + ->label('Décliner') |
| 82 | + ->icon('heroicon-s-x-mark') |
| 83 | + ->color('warning') |
| 84 | + ->modalHeading(__('Voulez vous décliner cet article')) |
| 85 | + ->successNotificationTitle(__('Opération effectuée avec succès')) |
| 86 | + ->requiresConfirmation() |
| 87 | + ->modalIcon('heroicon-s-x-mark') |
| 88 | + ->action(function ($record): void { |
| 89 | + $record->declined_at = now(); |
| 90 | + $record->approved_at = null; |
| 91 | + $record->save(); |
| 92 | + }), |
| 93 | + // DeclinedAction::make('declined'), |
68 | 94 | Tables\Actions\DeleteAction::make('delete'), |
69 | 95 | ]), |
70 | 96 |
|
71 | 97 | ]) |
72 | 98 | ->bulkActions([ |
73 | 99 | Tables\Actions\BulkActionGroup::make([ |
| 100 | + BulkAction::make('approved') |
| 101 | + ->label('Approuver la sélection') |
| 102 | + ->icon('heroicon-s-check') |
| 103 | + ->color('success') |
| 104 | + ->action(fn (Collection $records) => $records->each->update(['approved_at' => now(), 'declined_at' => null])) |
| 105 | + ->deselectRecordsAfterCompletion() |
| 106 | + ->requiresConfirmation() |
| 107 | + ->modalIcon('heroicon-s-check') |
| 108 | + ->modalHeading('Approuver') |
| 109 | + ->modalSubheading('Voulez-vous vraiment approuver ces articles ?') |
| 110 | + ->modalButton('Confirmer'), |
| 111 | + BulkAction::make('declined') |
| 112 | + ->label('Décliner la sélection') |
| 113 | + ->icon('heroicon-s-x-mark') |
| 114 | + ->color('warning') |
| 115 | + ->action(fn (Collection $records) => $records->each->update(['declined_at' => now(), 'approved_at' => null])) |
| 116 | + ->deselectRecordsAfterCompletion() |
| 117 | + ->requiresConfirmation() |
| 118 | + ->modalIcon('heroicon-s-x-mark') |
| 119 | + ->modalHeading('Décliner') |
| 120 | + ->modalSubheading('Voulez-vous vraiment décliner ces articles ?') |
| 121 | + ->modalButton('Confirmer'), |
| 122 | + |
74 | 123 | Tables\Actions\DeleteBulkAction::make(), |
75 | 124 | ]), |
76 | 125 | ]); |
|
0 commit comments