Set LatestTeam when switching in tenant menu

I see in the docs how to set the latest team and use the HasDefaultTenant contract, but don't see any way to tap into the tenant select menu to set the latest team when the user changes that. What's the best way to accomplish that?
Solution:
I figured out a way to not use custom navigation and everything seems to be working fine now. Seems like this shouldn't break the tenant switching menu though.
Jump to solution
4 Replies
Jon Mason
Jon MasonOP14mo ago
Seems like I could possibly listen for the TenantSet event.. I'm not sure of the issue I'm running into actually. I removed the HasDefaultTenant contract, and I'm still unable to change tenants. It just refreshes and always goes back to the same tenant. I thought it was because of the default tenant thing I was trying to add and maybe because the database field wasn't getting updated with the latest_team_id, but even after removing it and nulling out that field, I'm still unable to change tenants for some reason. Anyone have any idea why the tenant switching menu wouldn't work? You can select a team, but it always goes back to the same one. I figured out if I comment out my custom navigation, it starts working...I don't get that.
//->navigation(function (NavigationBuilder $builder): NavigationBuilder {
// return $builder->items([
// NavigationItem::make('Dashboard')
// ->icon('heroicon-o-home')
// ->isActiveWhen(fn (): bool => request()->routeIs('filament.app.pages.dashboard'))
// ->url(
// fn () => Dashboard::getUrl()
// ),
// NavigationItem::make('Locations')
// ->icon('heroicon-o-map-pin')
// ->isActiveWhen(fn (): bool => request()->routeIs('filament.app.resources.locations.index'))
// ->url(fn () => LocationResource::getUrl()),
// ]);
// });
//->navigation(function (NavigationBuilder $builder): NavigationBuilder {
// return $builder->items([
// NavigationItem::make('Dashboard')
// ->icon('heroicon-o-home')
// ->isActiveWhen(fn (): bool => request()->routeIs('filament.app.pages.dashboard'))
// ->url(
// fn () => Dashboard::getUrl()
// ),
// NavigationItem::make('Locations')
// ->icon('heroicon-o-map-pin')
// ->isActiveWhen(fn (): bool => request()->routeIs('filament.app.resources.locations.index'))
// ->url(fn () => LocationResource::getUrl()),
// ]);
// });
Solution
Jon Mason
Jon Mason14mo ago
I figured out a way to not use custom navigation and everything seems to be working fine now. Seems like this shouldn't break the tenant switching menu though.
oliverbusk
oliverbusk11mo ago
Hey Jon. How did you end up solving this? I have the exact same problem..
Andrew Wallo
Andrew Wallo11mo ago
Create a listener for the TenantSet event from Filament. Inside of that listener, update the current team id of the user.
Want results from more Discord servers?
Add your server