#How to dispatch an event from a Notification Action

17 messages · Page 1 of 1 (latest)

urban totem
#

I've been trying to dispatch an event from a Notification Action but it's not working.

using ->dispatch or ->dispatchSelf seems to do nothing.
I've searched around and tried to use ->action() and dispatch using $livewire->dispatch() but action seems to not work on notification Actions.

How can I rly dispatch an event from a Notification action?

Notification::make()
  ->success()
  ->title('Portador criado com sucesso!')
  ->actions([                                   \Filament\Notifications\Actions\Action::make('view')
       ->label('Ver Portador')
    // ->url('/admin/business/clients/' .$client->id.'/edit?activeRelationManager=2',true)
       ->dispatchSelf('test-created')
                                    ])
  ->send();

Further down in my Resource, there's my method that is attempting to listen to the dispatch event but it never gets there.

 #[On('test-event')]
    public function test()
    {
        dd('here');
    }

Any Thoughts?

final mossBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

uncut junco
#

I think you should use dispatch() instead of dispatchSelf and be careful of the naming. You are dispatching test-created and listening for test-event

urban totem
stiff pasture
#

You have defined an ->action() method. So it won’t do anything on click.

urban totem
carmine bobcat
stiff pasture
#

Actions aren’t livewire components so they aren’t going to just do a dispatch by themselves.

urban totem
# stiff pasture That’s my point.

Oh sorry for my misunderstanding then, so what do you suggest? Have an action method as well as a dispatch one? I've tried to dispatch it from the ->action() method and my perception was that it doesn't even go into ->action() method, even a simple dd inside the ->action() method doesn't work.

stiff pasture
#

Something like this, maybe.

Action::make('view')
  ->label('Ver Portador')
  ->action(fn ($livewire) => $livewire->dispatch('test-event')
urban totem
#

Can it be any behavior with it being a Notification Action?

stiff pasture
#

hmm. according to the docs ->dispatch() should work.

        Action::make('undo')
            ->color('gray')
            ->dispatch('undoEditingPost', [$post->id]),
hybrid pine
#

Having the same issue, were you able to work around this @urban totem ?