Notification action not working

Notification::make()
->title('Copy your token')
->body('Make sure to copy your new token now. You won\'t be able to see it again.')
->persistent()
->success()
->actions([
Action::make('copy')
->button()
->icon('heroicon-o-clipboard-document')
->action(function ($livewire) use ($plainTextToken) {
dd($plainTextToken);
ray('plainTextToken', $plainTextToken);
$livewire->js(
'window.navigator.clipboard.writeText("' . $plainTextToken . '");
$tooltip("' . __('Copied to clipboard') . '", { timeout: 1500 });'
);
}),
])
->send();
Notification::make()
->title('Copy your token')
->body('Make sure to copy your new token now. You won\'t be able to see it again.')
->persistent()
->success()
->actions([
Action::make('copy')
->button()
->icon('heroicon-o-clipboard-document')
->action(function ($livewire) use ($plainTextToken) {
dd($plainTextToken);
ray('plainTextToken', $plainTextToken);
$livewire->js(
'window.navigator.clipboard.writeText("' . $plainTextToken . '");
$tooltip("' . __('Copied to clipboard') . '", { timeout: 1500 });'
);
}),
])
->send();
Nothing get's executed when the button is clicked, does anyone know why?
2 Replies
emil
emil2w ago
How does the rest of your code looks like? Does it work without the custom actions in there?
LeandroFerreira
this is a static action. I think you can't use the action method. I know you can dispatch an event like this
Action::make('view')
->dispatch('copy-plain-text-token', ['token' => 'xxx']),
Action::make('view')
->dispatch('copy-plain-text-token', ['token' => 'xxx']),
You could use this approach to listen for a livewire event
document.addEventListener('livewire:init', () => {
Livewire.on('copy-plain-text-token', (event) => {
navigator.clipboard.writeText(event.token);
});
});
document.addEventListener('livewire:init', () => {
Livewire.on('copy-plain-text-token', (event) => {
navigator.clipboard.writeText(event.token);
});
});
Want results from more Discord servers?
Add your server