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:
```php public function init(): void { $this->dispatch('open-modal', id: 'setUsernameModal'); }...
Jump to solution
15 Replies
awcodes
awcodes3mo ago
And what is in your set-username view? That is the modal right?
Srccode
Srccode3mo ago
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
<?php

namespace App\Livewire;

use Livewire\Component;

class SetUsername extends Component
{
public function render()
{
$this->openModal();
return view('livewire.set-username');
}

public function openModal(): void
{
$this->dispatch('open-modal', 'set-username');
}

}
<?php

namespace App\Livewire;

use Livewire\Component;

class SetUsername extends Component
{
public function render()
{
$this->openModal();
return view('livewire.set-username');
}

public function openModal(): void
{
$this->dispatch('open-modal', 'set-username');
}

}
awcodes
awcodes3mo ago
Should it show before they interact with the login form?
Srccode
Srccode3mo ago
No right after the user logs in and the dashboard is shown
awcodes
awcodes3mo ago
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.
Srccode
Srccode3mo ago
Thank you for your answer. I'll see what I can do here.
LeandroFerreira
LeandroFerreira3mo ago
what do you think about a custom widget in the dashboard page? something like this:
Solution
LeandroFerreira
LeandroFerreira3mo ago
public function init(): void
{
$this->dispatch('open-modal', id: 'setUsernameModal');
}
public function init(): void
{
$this->dispatch('open-modal', id: 'setUsernameModal');
}
<x-filament-widgets::widget>
<x-filament::modal wire:init="init" id="setUsernameModal">
<div>...</div>
</x-filament::modal>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::modal wire:init="init" id="setUsernameModal">
<div>...</div>
</x-filament::modal>
</x-filament-widgets::widget>
Srccode
Srccode3mo ago
Thank you so much. I'll try this out.
awcodes
awcodes3mo ago
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. 🙂
Srccode
Srccode3mo ago
Hey! I added the code in the widget but it is throwing this error. can you help with this?
No description
LeandroFerreira
LeandroFerreira3mo ago
hey! I just wanted to throw out a suggestion 😅 ! I really admire you 💛
awcodes
awcodes3mo ago
No worries. All good.😊
Srccode
Srccode3mo ago
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.
Want results from more Discord servers?
Add your server
More Posts
Correct way to add/create a Livewire table column component?I have a table that when clicked opens a modal and runs some calculations. The calculations are expcreateOptionForm()when i create resource from createOptionForm getting error in my form i have hidden field $get inside loop null, outside loop it is notI am trying to access the $get of a wizard multi step form, but I can't access it inside my loop. ThInfolist/form not appears in relation managerI have a relation manager that get displayed in the resource edit page. The table is rendered correcWhen using groups in a table, select each row individually instead of the entire groupWhen using groups in a table, if I click on the checkbox for each row, the entire group is selected.Multiple Select with relationship in Builder Block is not workingHi guys! I was wondering if the Select with many to many relationship should work, without any speciLoading indicator in paginatorIs it possible to add a loading indicator to all the table when clicking the next page in the paginaVisible for Attach Action In Relation ManagerHi all , currently im developing a project that requires me to use belongstomany relationship. i hNeed help to overwrite the default create action in a resource /create page.I'm having a hard time trying to overwrite the default create process in a specific /create page ofMultiple lines of description on Text Column?I have a Users resource with a text column for a user's name. I then use the `description()` method