Skip to content

Commit

Permalink
Merge pull request #100 from RafaelBlum/notification-delete
Browse files Browse the repository at this point in the history
feat: Add botões de deleção com notificações no resources
  • Loading branch information
icarojobs authored Aug 13, 2024
2 parents a95bf9b + b839bda commit 2b86697
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/Filament/Resources/CustomerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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([
Expand Down
7 changes: 7 additions & 0 deletions app/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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([
Expand Down
32 changes: 32 additions & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit 2b86697

Please sign in to comment.