Notification appears 3 times

Every time I open the edit page, or click the action, or confirm, I get a notification. How can I only get a notification after a confirm?
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
Action::make('accept')
->color('success')
->label('Accept')
->disabled(!auth()->user()->can('status_expense'))
->action(function (array $data): void {
$this->record->status = Status::where('name', 'Accepted')->first()->id;
$this->record->save();

})
->requiresConfirmation()
->successNotification(
Notification::make()
->success()
->title('Form Updated')
->body('The expense was accepted.')
->send(),
),
Action::make('reject')
->color('danger')
->label('Reject')
->disabled(!auth()->user()->can('status_expense'))
->requiresConfirmation()
->action(function (array $data): void {
$this->record->status = Status::where('name', 'Rejected')->first()->id;
$this->record->save();
})
];
}
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
Action::make('accept')
->color('success')
->label('Accept')
->disabled(!auth()->user()->can('status_expense'))
->action(function (array $data): void {
$this->record->status = Status::where('name', 'Accepted')->first()->id;
$this->record->save();

})
->requiresConfirmation()
->successNotification(
Notification::make()
->success()
->title('Form Updated')
->body('The expense was accepted.')
->send(),
),
Action::make('reject')
->color('danger')
->label('Reject')
->disabled(!auth()->user()->can('status_expense'))
->requiresConfirmation()
->action(function (array $data): void {
$this->record->status = Status::where('name', 'Rejected')->first()->id;
$this->record->save();
})
];
}
15 Replies
Dan Harrin
Dan Harrin2y ago
dont ->send() we do it at the correct time
Matthew
MatthewOP2y ago
Thus, where is the correct place? the confirmation is before the notification, so why is it being sent when I havent technically confirmed yet?
Dan Harrin
Dan Harrin2y ago
ive just seen, this is a custom action you can just move it inside the action() after saving and then send() successNotification() is only for our built-in actions like EditAction and CreateAction, allowing you to customize the built-in notification we provide
Matthew
MatthewOP2y ago
Great! This works. One more thing: I have to refresh for the change to take place. Is there some filament built-in command that allows you to see the changes immediately?
Matthew
MatthewOP2y ago
Thank you! This works
Matthew
MatthewOP2y ago
One more thing 😅, there seems to be a visual error when I click the view action @Leandro Ferreira
Matthew
MatthewOP2y ago
Im not sure whats causing the status to display like that.
LeandroFerreira
weird... can you show the code of the select field?
Matthew
MatthewOP2y ago
$pendingStatusId = Status::where('name', 'Pending')->first()->id;
// ...
Select::make('status')
->label('Status')
->default($pendingStatusId)
->options(Status::all()->pluck('name', 'id'))
->searchable()
->disabled(!auth()->user()->can('status_expense')),
$pendingStatusId = Status::where('name', 'Pending')->first()->id;
// ...
Select::make('status')
->label('Status')
->default($pendingStatusId)
->options(Status::all()->pluck('name', 'id'))
->searchable()
->disabled(!auth()->user()->can('status_expense')),
very weird... i just tried this on firefox, and it doesnt happern
Matthew
MatthewOP2y ago
Matthew
MatthewOP2y ago
but firefox doesnt load the attachment, but chrome does...
LeandroFerreira
try to update composer and after run php artisan filament:upgrade I don't know this issue..
Matthew
MatthewOP2y ago
unfortunately, neither of them solve this issue Maybe Dan has an idea?
Dan Harrin
Dan Harrin2y ago
i dont know, sorry open an issue if you can create a reproduction repository
Want results from more Discord servers?
Add your server