F
Filament14mo ago
Matthew

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 Harrin14mo ago
dont ->send() we do it at the correct time
Matthew
Matthew14mo 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 Harrin14mo 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
Matthew14mo 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
Matthew14mo ago
Thank you! This works
Matthew
Matthew14mo ago
One more thing 😅, there seems to be a visual error when I click the view action @Leandro Ferreira
Matthew
Matthew14mo ago
Im not sure whats causing the status to display like that.
LeandroFerreira
LeandroFerreira14mo ago
weird... can you show the code of the select field?
Matthew
Matthew14mo 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
Matthew14mo ago
Matthew
Matthew14mo ago
but firefox doesnt load the attachment, but chrome does...
LeandroFerreira
LeandroFerreira14mo ago
try to update composer and after run php artisan filament:upgrade I don't know this issue..
Matthew
Matthew14mo ago
unfortunately, neither of them solve this issue Maybe Dan has an idea?
Dan Harrin
Dan Harrin14mo ago
i dont know, sorry open an issue if you can create a reproduction repository