Chaining Actions

I have Reset Password Action. That action is going to require confirmation and then change the password. I have that working. How do i then after that display a slideover() form with that temporary password? Basically, how do i launch another modal/form within ->after()?
15 Replies
Mark Chaney
Mark ChaneyOP2y ago
I have everything pretty much built out except initiating that second form.
cheesegrits
cheesegrits2y ago
Very interested to see if there is a solution for this, as I have several actions that could do with this kind of treatment - providing feedback after the initial modal form is displayed and submitted. Atm I'm having to make do with notifications.
Mark Chaney
Mark ChaneyOP2y ago
@cheesegrits I needed to move on myself an simply doing an notification too. Obviously I could do my own modal and use emit to launch it, but i dont feel i should have to recreate all that from scratch
cheesegrits
cheesegrits2y ago
I suspect it may be something that happens in v3 at some point. The new Actions package is getting a lot of love.
Dan Harrin
Dan Harrin2y ago
i dont know how id implement nested modals
cheesegrits
cheesegrits2y ago
I'm not sure about MAC's usage, but for me it's more chained than nested. Although I guess that depends on how one defines "nested". The usage I find myself wanting is triggering subsequent actions that receive the results of the previous one.
Mark Chaney
Mark ChaneyOP2y ago
https://github.com/wire-elements/modal does a great job with being able to do that
GitHub
GitHub - wire-elements/modal: Livewire component that provides you ...
Livewire component that provides you with a modal that supports multiple child modals while maintaining state. - GitHub - wire-elements/modal: Livewire component that provides you with a modal that...
Mark Chaney
Mark ChaneyOP2y ago
but yes, we are mainly talking about actions after each other
cheesegrits
cheesegrits2y ago
I'd like to be able to return a data array from one action, and pass it in to the mountUsing of another, and/or some kind of "trigger" function which determines whether the next action runs ... top of my head ...
ChainedActions::make('do-what-do')
->actions([
Action::make('do')
->form([
//
])
->mountUsing(fn (Forms\ComponentContainer $form) => $form->fill([
//
]))
->action(function (array $data) {
// do something
return [
'result' => $doThingWorked ? 'ok' : 'ooops',
'thing' => $something,
];
}),
Action::make('what-do-now')
->form([
//
])
->mountUsing(fn (Forms\ComponentContainer $form, array $data) => $form->fill([
// fill according to result of previous in $data
'thing' => $data['thing'],
]))
->action(function (array $data) {
// do something
})
// control whether to run second action
->trigger(fn (array $data) => $data['result'] !== 'ok'),
]);
ChainedActions::make('do-what-do')
->actions([
Action::make('do')
->form([
//
])
->mountUsing(fn (Forms\ComponentContainer $form) => $form->fill([
//
]))
->action(function (array $data) {
// do something
return [
'result' => $doThingWorked ? 'ok' : 'ooops',
'thing' => $something,
];
}),
Action::make('what-do-now')
->form([
//
])
->mountUsing(fn (Forms\ComponentContainer $form, array $data) => $form->fill([
// fill according to result of previous in $data
'thing' => $data['thing'],
]))
->action(function (array $data) {
// do something
})
// control whether to run second action
->trigger(fn (array $data) => $data['result'] !== 'ok'),
]);
awcodes
awcodes2y ago
I don’t know how that would be accomplished but I like the idea of it. Something like Laravel’s new Process but for actions.
cheesegrits
cheesegrits2y ago
Perfect world, the array of actions would could be any length, it just checks the trigger (if present) for each in turn with the current response $data (or just runs it if no trigger).
awcodes
awcodes2y ago
Seems like a wizard would be easier though. 😜 Especially for a11y. Might actually be possible though by maintaining the form data at the parent level and injecting it through evaluation.
cheesegrits
cheesegrits2y ago
I was going to say, this is kind of "Action Wizards". Most of my cases are relatively simple though, of just wanting to either handle an error from the main action (where the user needs to choose between options for remedial action), or (like MAC's example) give them some result from the main action that doesn't fit into a notification paradigm.
awcodes
awcodes2y ago
No doubt. I think that’s where halt() fits in but it’s not as straightforward as that. But I definitely see the point and the use case.
cheesegrits
cheesegrits2y ago
Oh, right, yeah, would need a halt() I guess. Or have the trigger() return true (run action), null (no opinion, ask the next action) or false (halt). The more I think about it, the more use cases I see in my apps for it, and the more logic I could offload to actions.
Want results from more Discord servers?
Add your server