|
14 | 14 | use Filament\Forms\Components\Select; |
15 | 15 | use Filament\Notifications\Notification; |
16 | 16 | use Filament\Resources\Resource; |
| 17 | +use Filament\Support\Enums\MaxWidth; |
17 | 18 | use Filament\Tables; |
18 | 19 | use Filament\Tables\Actions\BulkAction; |
| 20 | +use Filament\Tables\Actions\BulkActionGroup; |
19 | 21 | use Filament\Tables\Actions\DeleteBulkAction; |
20 | 22 | use Filament\Tables\Columns\TextColumn; |
21 | 23 | use Filament\Tables\Enums\FiltersLayout; |
@@ -101,40 +103,49 @@ public static function table(Table $table): Table |
101 | 103 | ] |
102 | 104 | ) |
103 | 105 | ->bulkActions([ |
104 | | - Tables\Actions\BulkActionGroup::make([ |
105 | | - |
106 | | - BulkAction::make('change-status') |
107 | | - ->label(__('map_points.buttons.change_status')) |
108 | | - ->form([ |
109 | | - Select::make('status') |
110 | | - ->label(__('map_points.fields.status')) |
111 | | - ->options(Status::options()) |
112 | | - ->required(), |
113 | | - ]) |
114 | | - ->action(function (array $data, Collection $records): void { |
| 106 | + BulkActionGroup::make([ |
| 107 | + BulkAction::make('change-status-verified') |
| 108 | + ->label(__('map_points.buttons.change_status_verified')) |
| 109 | + ->action(function (Collection $records): void { |
115 | 110 | $recordsWithoutIssues = $records->filter(function ($record) { |
116 | | - return $record->issues->isEmpty(); |
117 | | - }); |
| 111 | + $record->load('problems'); |
118 | 112 |
|
119 | | - $recordsWithoutIssues->map->changeStatus(Status::from($data['status'])); |
120 | | - |
121 | | - if ($records->count() === $recordsWithoutIssues->count()) { |
122 | | - Notification::make('success_status_changed') |
123 | | - ->body(__('map_points.notifications.status_changed.success')) |
124 | | - ->success() |
125 | | - ->send(); |
126 | | - } else { |
127 | | - Notification::make('warning_status_changed') |
128 | | - ->body(__('map_points.notifications.status_changed.warning', [ |
129 | | - 'count' => $records->count() - $recordsWithoutIssues->count(), |
130 | | - ])) |
131 | | - ->warning() |
132 | | - ->send(); |
133 | | - } |
| 113 | + return $record->problems->isEmpty(); |
| 114 | + }); |
| 115 | + Point::whereIn('id', $recordsWithoutIssues->pluck('id')->toArray()) |
| 116 | + ->update([ |
| 117 | + 'verified_at' => now(), |
| 118 | + ]); |
| 119 | + Notification::make('success_status_changed') |
| 120 | + ->body(__('map_points.notifications.status_change_verified')) |
| 121 | + ->success() |
| 122 | + ->send(); |
134 | 123 | }) |
135 | 124 | ->deselectRecordsAfterCompletion() |
136 | 125 | ->icon('heroicon-o-check') |
137 | | - ->color('warning') |
| 126 | + ->color('primary') |
| 127 | + ->requiresConfirmation(), |
| 128 | + |
| 129 | + BulkAction::make('change-status-unverified') |
| 130 | + ->label(__('map_points.buttons.change_status_unverified')) |
| 131 | + ->action(function (Collection $records): void { |
| 132 | + $recordsWithoutIssues = $records->filter(function ($record) { |
| 133 | + $record->load('problems'); |
| 134 | + |
| 135 | + return $record->problems->isEmpty(); |
| 136 | + }); |
| 137 | + Point::whereIn('id', $recordsWithoutIssues->pluck('id')->toArray()) |
| 138 | + ->update([ |
| 139 | + 'verified_at' => null, |
| 140 | + ]); |
| 141 | + Notification::make('success_status_changed') |
| 142 | + ->body(__('map_points.notifications.status_change_verified')) |
| 143 | + ->success() |
| 144 | + ->send(); |
| 145 | + }) |
| 146 | + ->deselectRecordsAfterCompletion() |
| 147 | + ->icon('heroicon-o-exclamation-triangle') |
| 148 | + ->color('danger') |
138 | 149 | ->requiresConfirmation(), |
139 | 150 |
|
140 | 151 | BulkUpdateInfo::make(), |
@@ -178,8 +189,9 @@ public static function table(Table $table): Table |
178 | 189 | }); |
179 | 190 | }) |
180 | 191 | ->label(__('map_points.buttons.delete')), |
| 192 | + ]) |
| 193 | + ->dropdownWidth(MaxWidth::Medium->value), |
181 | 194 |
|
182 | | - ]), |
183 | 195 | ]) |
184 | 196 | ->deferLoading(); |
185 | 197 | } |
|
0 commit comments