Trying to dispacth events inside filament 3 form
I'm trying dispatch this event inside my form, but the event are not being dispatched, i'm doing something wrong?
public function setHotelInfo($lunaId, Set $set): void
{
try {
$hotelLuna = new HotelLuna();
$hotels = $hotelLuna->info($lunaId)['hotels'];
if ($hotels[0]['id'] == 1) {
throw new \Exception('deu ruim', 500);
}
//do some stuff
} catch (\Exception | \Throwable $e) {
$this->dispatch(
'openModal',
title: 'user.errors.duplicated_collaborator',
description:'user.messages.duplicate_collaborator',
status:ExceptionLevelsEnum::WARNING->getLabel(),
actionCancel:['action' => 'redirectTo', 'label' => 'common.actions.cancel', 'urlRedirect' => 'App\Filament\Resources\UserResource\Pages\ListUsers'],
actionContinue:['action' => 'close', 'label' => 'common.actions.edit_data']
);
}
}
Sorry but we cannot see screenshots located on your computer. Can you share the code?
@herman_onfly And how are you catching this notification on the frontend? We need the blade file also to see what is going on.
@Merklin Thats my notification code
use Illuminate\View\Factory;
use Illuminate\View\View;
use Livewire\Component;
class Notification extends Component
{
public string $title;
public string $description;
public string $status = 'success';
public string $icon = 'heroicon-c-check-circle';
public mixed $actionCancel = [
'label' => ' ',
'action' => ' ',
];
public mixed $actionContinue = [
'label' => ' ',
'action' => ' ',
];
protected $listeners = [
'redirectTo',
'close',
'openModal',
];
public function redirectTo($url): void
{
$this->redirect($url::getUrl());
}
public function close(): void
{
$this->dispatch('close-modal', id:'notification');
}
public function openModal(
string $title,
string $description,
array $actionContinue = [],
array $actionCancel = [],
string $status = 'success'
): void {
$this->title = $title;
$this->description = $description;
$this->status = $status;
$this->actionCancel = $actionCancel;
$this->actionContinue = $actionContinue;
switch ($this->status) {
case ExceptionLevelsEnum::WARNING->getLabel():
$this->icon = 'heroicon-s-exclamation-circle';
break;
case ExceptionLevelsEnum::DANGER->getLabel():
$this->icon = 'heroicon-c-x-circle';
break;
case ExceptionLevelsEnum::INFO->getLabel():
$this->icon = 'heroicon-c-information-circle';
break;
}
$this->dispatch('open-modal', id:'notification');
}
public function render(): Factory|View
{
return view('livewire.modal.notification');
}
}
``
Seldom do people ask themselves.. 'Why am I trying to do this? What do I hope to achieve?'.
What's the problem you're trying to solve?
Please or to participate in this conversation.