Displaying a modal after action has been performed

Hi - I want to create a table action (like add it on each row) where a user clicks on a button, it performs an action (connection-check in this case) which returns either true or false. Afterwards I want to see a modal with either "success" or "failure". Now from what I get so far, I can create modals BEFORE an action has been performed (like confirmation modals or form-modals), but how do I do that AFTERWARDS? I could do the workarround by opening a modal, adding a button and update said modal, but that is not elegant enough for me. Is there a way to do it like "click button" -> "perform action" -> "show modal with content concering the action-result"? Thanks in advance. 🙂
Solution:
Okay - here is what I ended up with: ``` Tables\Actions\Action::make('checkConnection') ->label('Verbindung prüfen') ->button()...
Jump to solution
18 Replies
Husky110
Husky110OP16mo ago
Okay - I was able to stich something together by utilizing the ->form-function and mountUsing. Only problem left is that I had to add an action there for the modal to even show up and now there is a "Submit"-Button. If someone has an idea on how to suppress that, that would actually do the trick. 🙂 What I have so far:
Tables\Actions\Action::make('checkConnection')
->label('Verbindung prüfen')
->button()
->form([
Forms\Components\TextInput::make('status')->disabled(),
])
->mountUsing(function ($form,$record){
$form->fill([
'status' => MyClass::myAction() ? 'Success' : 'Error'
]);
})
->action(true),
Tables\Actions\Action::make('checkConnection')
->label('Verbindung prüfen')
->button()
->form([
Forms\Components\TextInput::make('status')->disabled(),
])
->mountUsing(function ($form,$record){
$form->fill([
'status' => MyClass::myAction() ? 'Success' : 'Error'
]);
})
->action(true),
toeknee
toeknee16mo ago
Are you using Tables outside or tables inside the admin panel?
Husky110
Husky110OP16mo ago
inside
ZedoX
ZedoX16mo ago
Isn't this the purpose of notifications? IIRC notifications alignment can be changed to center the notifications, making it look like a modal?
toeknee
toeknee16mo ago
Exactly what I was going to say @ZedoX this is the exact usecase of Notifications
Husky110
Husky110OP16mo ago
okay @toeknee and @ZedoX - Thanks for that input. 🙂 But how would I have to modify my code (see above) so send that Notification inside a table-action? Something like this? I need a starting-point of sort... 😅
->action(fn() => Notification::make('check')->send())
->action(fn() => Notification::make('check')->send())
toeknee
toeknee16mo ago
Exactly You cn then do a update on that action too to check it in the db
Husky110
Husky110OP16mo ago
And do you know how to center it like @ZedoX said? Cause I need that only for that one specific notation and not globally...
toeknee
toeknee16mo ago
You can't as far as I am aware at present. Personally, all notifications / notifiable actions from a UX perspective should be in the same place
Solution
Husky110
Husky11016mo ago
Okay - here is what I ended up with:
Tables\Actions\Action::make('checkConnection')
->label('Verbindung prüfen')
->button()
->action(
fn($record) =>
Notification::make('checkCon')
->body(function () use ($record){
try{
return MyClass::myAction() ? 'Erfolgreich' : 'Fehlgeschlagen';
} catch (\Exception){
return 'Fehler';
}
})
->persistent()
->send()
),
Tables\Actions\Action::make('checkConnection')
->label('Verbindung prüfen')
->button()
->action(
fn($record) =>
Notification::make('checkCon')
->body(function () use ($record){
try{
return MyClass::myAction() ? 'Erfolgreich' : 'Fehlgeschlagen';
} catch (\Exception){
return 'Fehler';
}
})
->persistent()
->send()
),
Thanks @toeknee and @ZedoX. 🙂
toeknee
toeknee16mo ago
Welcomes!
Husky110
Husky110OP16mo ago
Can you mark my last message as solution please? I don't see the Apps-submenu in Discord...
toeknee
toeknee16mo ago
You can hover and click the three dots
Husky110
Husky110OP16mo ago
toeknee
toeknee16mo ago
checking
Husky110
Husky110OP16mo ago
@Dennis Koch - Thank you! Is there something up with the Bot?
toeknee
toeknee16mo ago
Ahh it's a app version issue, update discord and it should come back
Husky110
Husky110OP16mo ago
Ah - thanks! Works now. 🙂 Gotta love the Filament-Helpers. 😁
Want results from more Discord servers?
Add your server