GuavaCZ / calendar

MIT License
140 stars 13 forks source link

[Help]: Rendering custom modal to view event details #13

Closed Altffenser closed 4 months ago

Altffenser commented 4 months ago

What feature would you like to add?

I would like to display a custom modal, either by passing the view as an instruction or by triggering with Livewire's dispatch() method.

The problem is that I get neither, the onEventClick() event somehow fails to execute the instruction. I have tried with:

public function onEventClick(array $info = [], ?string $action = null): void
{
    $this->dispatch('view-event-details', data: $info['event']);
}

and (example from Filament Doc.):

public function onEventClick(array $info = [], ?string $action = null): void
{
    Action::make('delete')
    ->action(fn (LocalEvent $record) => $record->delete())
    ->requiresConfirmation()
}

Nothing is happens. Some help is appreciable.

Notes

No response

Altffenser commented 4 months ago

Weird thing, using dd($info["event"]) does work (or at least it does something).

lukas-frey commented 4 months ago

You can't just return the Action, you need to mount it.

If you're trying to mount a different action onEventClick, simply create a new action in your livewire class, such as:


public function customAction() {
return Action::make('custom`)
->requiresConfirmation()
// Whatever else you want to do with the action
;
}

and remove your onEventClick function (don't override it). You simply override the $defaultEventClickAction and set it to your new action:

protected ?string $defaultEventClickAction = 'custom';

Just make sure to handle the authorization in the authorize method, the ability parameter will be the name of the action. For testing purposes you can just return true, but on production you should make sure that the user is allowed to perform the action.

EDIT:

But if you only want to add a confirmation dialog to the deleteAction, you can just override the deleteAction method and modify the DeleteAction there.

Altffenser commented 4 months ago

You can't just return the Action, you need to mount it.

If you're trying to mount a different action onEventClick, simply create a new action in your livewire class, such as:

public function customAction() {
return Action::make('custom`)
->requiresConfirmation()
// Whatever else you want to do with the action
;
}

and remove your onEventClick function (don't override it). You simply override the $defaultEventClickAction and set it to your new action:

protected ?string $defaultEventClickAction = 'custom';

Just make sure to handle the authorization in the authorize method, the ability parameter will be the name of the action. For testing purposes you can just return true, but on production you should make sure that the user is allowed to perform the action.

EDIT:

But if you only want to add a confirmation dialog to the deleteAction, you can just override the deleteAction method and modify the DeleteAction there.

Thank you for the time. You're amazing! Solved.