Skip to content

Commit

Permalink
Merge pull request #9 from tomhatzer/main
Browse files Browse the repository at this point in the history
Fixes current_team_id not being updated
  • Loading branch information
stephenjude authored May 14, 2024
2 parents 9081147 + b7cc1f1 commit 4621042
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions stubs/App/Listeners/SwitchTeam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Listeners;

use Filament\Events\TenantSet;
use Laravel\Jetstream\Features;

class SwitchTeam
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(TenantSet $event): void
{
if (Features::hasTeamFeatures()) {
$user = $event->getUser();

$team = $event->getTenant();

$user->switchTeam($team);
}
}
}

10 changes: 10 additions & 0 deletions stubs/App/Providers/Filament/AppPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use App\Filament\Pages\EditProfile;
use App\Filament\Pages\EditTeam;
use App\Listeners\CreatePersonalTeam;
use App\Listeners\SwitchTeam;
use App\Models\Team;
use Filament\Events\Auth\Registered;
use Filament\Events\TenantSet;
use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
Expand Down Expand Up @@ -130,6 +132,14 @@ public function boot()
Registered::class,
CreatePersonalTeam::class,
);

/**
* Listen and switch team if tenant was changed
*/
Event::listen(
TenantSet::class,
SwitchTeam::class,
);
}

public function shouldRegisterMenuItem(): bool
Expand Down

0 comments on commit 4621042

Please sign in to comment.