Open a Modal when user logs in
Hello. I have a custom livewire component modal that i want to show every time a user logs in on the dashboard page but I cant figure out how to dispatch the event to trigger the opening of thew modal. Any help will be appreciated.
This is how I am rendering the modal view in my provider:
return $panel
->default()
->id('admin')
.......
->plugins([
FilamentShieldPlugin::make()
])
->renderHook(
'panels::auth.login.form.after',
fn () => view('auth.socialite.google')
)
->renderHook(
PanelsRenderHook::CONTENT_END,
function (): View {
return view('livewire.set-username');
}
);
Solution:Jump to solution
```php
public function init(): void
{
$this->dispatch('open-modal', id: 'setUsernameModal');
}...
15 Replies
And what is in your set-username view? That is the modal right?
Yes. just a modal in the view file.
<x-filament::modal id="set-username">
<x-slot name="heading">
Modal heading
</x-slot>
</x-filament::modal>
This is my current livewire component
Should it show before they interact with the login form?
No right after the user logs in and the dashboard is shown
Ok, this could get complicated too, because including in the renderHook means it’s going to fire on every page in the panel.
I’m thinking it needs to be an alpine component so you can dispatch the open modal in alpines init() method. But you’ll also want to check that the user is only on the dashboard for the first time, with either cookies or localStorage. Either way, you’re going to want to handle most of this on the js side.
Could potentially use Session to handle it on the php side but I think you’ll still want to use alpine to launch it since the server has no idea about when the page has finished loading and rendering.
Thank you for your answer. I'll see what I can do here.
what do you think about a custom widget in the dashboard page?
something like this:
Solution
Thank you so much. I'll try this out.
Way cleaner. I feel dumb, thanks 😂. Still need to track the first visit though so it doesn’t show every time they go back to the dashboard. 🙂
Hey! I added the code in the widget but it is throwing this error. can you help with this?
hey! I just wanted to throw out a suggestion 😅 ! I really admire you 💛
Did you create a custom widget?
https://filamentphp.com/docs/3.x/panels/dashboard#custom-widgets
No worries. All good.😊
Yes i was making changes in the wrong file. I can see the modal now. Thank you so much for your help. This really helped my project a lot.