diff --git a/app/Filament/Resources/CustomerResource.php b/app/Filament/Resources/CustomerResource.php index 1a7b0a3..f77fc76 100644 --- a/app/Filament/Resources/CustomerResource.php +++ b/app/Filament/Resources/CustomerResource.php @@ -13,6 +13,7 @@ use Filament\Resources\Resource; use Filament\Support\RawJs; use Filament\Tables; +use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Table; class CustomerResource extends Resource @@ -125,6 +126,12 @@ public static function table(Table $table): Table ->actions([ Tables\Actions\ActionGroup::make([ Tables\Actions\EditAction::make(), + DeleteAction::make() + ->action(fn (Customer $record) => $record->delete()) + ->requiresConfirmation() + ->modalHeading('Deletar '. $table->getModelLabel()) + ->modalDescription('Tem certeza de que deseja excluir este '. $table->getModelLabel() .'? Isto não pode ser desfeito.') + ->modalSubmitActionLabel('Sim, deletar!'), ])->tooltip('Menu') ]) ->bulkActions([ diff --git a/app/Filament/Resources/ProductResource.php b/app/Filament/Resources/ProductResource.php index ebfc1ac..e8ea3c4 100644 --- a/app/Filament/Resources/ProductResource.php +++ b/app/Filament/Resources/ProductResource.php @@ -11,6 +11,7 @@ use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; +use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Table; class ProductResource extends Resource @@ -109,6 +110,12 @@ public static function table(Table $table): Table ->actions([ Tables\Actions\ActionGroup::make([ Tables\Actions\EditAction::make(), + DeleteAction::make() + ->action(fn (Product $record) => $record->delete()) + ->requiresConfirmation() + ->modalHeading('Deletar '. $table->getModelLabel()) + ->modalDescription('Tem certeza de que deseja excluir este '. $table->getModelLabel() .'? Isto não pode ser desfeito.') + ->modalSubmitActionLabel('Sim, deletar!'), ])->tooltip('Menu') ]) ->bulkActions([ diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 69a5c9a..1ce5fa2 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -13,6 +13,7 @@ use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Actions\Action; +use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; use App\Enums\PanelTypeEnum; @@ -87,6 +88,26 @@ public static function table(Table $table): Table ->actions([ Tables\Actions\ActionGroup::make([ Tables\Actions\EditAction::make(), + DeleteAction::make() + ->action(function(User $record){ + if ($record->customer == null) { + static::notificationDelete($record); + } else { + if($record->customer->orders->isEmpty()){ + static::notificationDelete($record); + return null; + } + Notification::make() + ->title('Não é possível excluir este usuário!') + ->body("Este usuário tem pedidos associados em andamento.") + ->danger() + ->send(); + } + }) + ->requiresConfirmation() + ->modalHeading('Deletar '. $table->getModelLabel()) + ->modalDescription('Tem certeza de que deseja excluir este '. $table->getModelLabel() .'? Isto não pode ser desfeito.') + ->modalSubmitActionLabel('Sim, deletar!'), Action::make('Editar tipo') ->icon('heroicon-o-pencil-square') @@ -115,6 +136,17 @@ public static function table(Table $table): Table ]); } + public static function notificationDelete(User $record): void + { + $record->delete(); + + Notification::make() + ->title('Excluído com sucesso!') + ->body("Usuário removido da sua carteira de clientes!") + ->success() + ->send(); + } + public static function getRelations(): array { return [