From ef6cacda1b74d8238df548c75b789618fa0fd597 Mon Sep 17 00:00:00 2001 From: Rafael Blum Date: Thu, 2 May 2024 10:59:07 -0300 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Add=20bot=C3=B5es=20de=20dele=C3=A7?= =?UTF-8?q?=C3=A3o=20com=20notifica=C3=A7=C3=B5es=20no=20resources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Filament/Resources/ProductResource.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Filament/Resources/ProductResource.php b/app/Filament/Resources/ProductResource.php index ebfc1ac..f9aabf0 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->getModel()) + ->modalDescription('Tem certeza de que deseja excluir este ? Isto não pode ser desfeito.') + ->modalSubmitActionLabel('Sim, deletar!'), ])->tooltip('Menu') ]) ->bulkActions([ From b839bda964bb3d43b7addbac5bd2864f0575b796 Mon Sep 17 00:00:00 2001 From: Rafael Blum Date: Thu, 9 May 2024 11:42:16 -0300 Subject: [PATCH 2/2] =?UTF-8?q?:sparkles:=20feat:=20Adicionado=20bot=C3=A3?= =?UTF-8?q?o=20de=20deletar=20produto,=20Usu=C3=A1rio=20e=20Cliente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Filament/Resources/CustomerResource.php | 7 +++++ app/Filament/Resources/ProductResource.php | 4 +-- app/Filament/Resources/UserResource.php | 32 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) 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 f9aabf0..e8ea3c4 100644 --- a/app/Filament/Resources/ProductResource.php +++ b/app/Filament/Resources/ProductResource.php @@ -113,8 +113,8 @@ public static function table(Table $table): Table DeleteAction::make() ->action(fn (Product $record) => $record->delete()) ->requiresConfirmation() - ->modalHeading('Deletar '. $table->getModel()) - ->modalDescription('Tem certeza de que deseja excluir este ? Isto não pode ser desfeito.') + ->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') ]) 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 [