From ca7191dd6ad44f38eabca68550ca175f09d52605 Mon Sep 17 00:00:00 2001 From: Tom Hatzer Date: Fri, 26 Apr 2024 17:25:01 +0200 Subject: [PATCH 1/7] Adds SetCurrentTeamId listener and event relation in AppPanelProvider.php --- stubs/App/Listeners/SetCurrentTeamId.php | 31 +++++++++++++++++++ .../Providers/Filament/AppPanelProvider.php | 9 ++++++ 2 files changed, 40 insertions(+) create mode 100644 stubs/App/Listeners/SetCurrentTeamId.php diff --git a/stubs/App/Listeners/SetCurrentTeamId.php b/stubs/App/Listeners/SetCurrentTeamId.php new file mode 100644 index 0000000..71c3c8a --- /dev/null +++ b/stubs/App/Listeners/SetCurrentTeamId.php @@ -0,0 +1,31 @@ +getUser(); + $user->switchTeam($event->getTenant()); + } + } +} + diff --git a/stubs/App/Providers/Filament/AppPanelProvider.php b/stubs/App/Providers/Filament/AppPanelProvider.php index b56c8c8..9883aef 100644 --- a/stubs/App/Providers/Filament/AppPanelProvider.php +++ b/stubs/App/Providers/Filament/AppPanelProvider.php @@ -7,6 +7,7 @@ use App\Filament\Pages\EditProfile; use App\Filament\Pages\EditTeam; use App\Listeners\CreatePersonalTeam; +use App\Listeners\SetCurrentTeamId; use App\Models\Team; use Filament\Events\Auth\Registered; use Filament\Facades\Filament; @@ -130,6 +131,14 @@ public function boot() Registered::class, CreatePersonalTeam::class, ); + + /** + * Listen and switch team if tenant was changed + */ + Event::listen( + TenantSet::class, + SetCurrentTeamId::class, + ); } public function shouldRegisterMenuItem(): bool From 2ce0559fb041e69439b1bf5a26728cea95bace9c Mon Sep 17 00:00:00 2001 From: Tom Hatzer Date: Fri, 26 Apr 2024 17:26:19 +0200 Subject: [PATCH 2/7] Adds import for TenantSet event --- stubs/App/Providers/Filament/AppPanelProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/App/Providers/Filament/AppPanelProvider.php b/stubs/App/Providers/Filament/AppPanelProvider.php index 9883aef..f00d9b7 100644 --- a/stubs/App/Providers/Filament/AppPanelProvider.php +++ b/stubs/App/Providers/Filament/AppPanelProvider.php @@ -10,6 +10,7 @@ use App\Listeners\SetCurrentTeamId; 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; From f9672cb148e68bbdffd2e84056b22b60d3f7701a Mon Sep 17 00:00:00 2001 From: Tom Hatzer Date: Fri, 26 Apr 2024 17:28:09 +0200 Subject: [PATCH 3/7] Removes unused import --- stubs/App/Listeners/SetCurrentTeamId.php | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/App/Listeners/SetCurrentTeamId.php b/stubs/App/Listeners/SetCurrentTeamId.php index 71c3c8a..becd105 100644 --- a/stubs/App/Listeners/SetCurrentTeamId.php +++ b/stubs/App/Listeners/SetCurrentTeamId.php @@ -3,7 +3,6 @@ namespace App\Listeners; use App\Models\Team; -use Filament\Events\Auth\Registered; use Filament\Events\TenantSet; use Laravel\Jetstream\Features; From 47d7408db5f347956ad113eee3b6602546061385 Mon Sep 17 00:00:00 2001 From: Tom Hatzer Date: Fri, 26 Apr 2024 17:29:02 +0200 Subject: [PATCH 4/7] Removes unused import --- stubs/App/Listeners/SetCurrentTeamId.php | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/App/Listeners/SetCurrentTeamId.php b/stubs/App/Listeners/SetCurrentTeamId.php index becd105..2ddeb1e 100644 --- a/stubs/App/Listeners/SetCurrentTeamId.php +++ b/stubs/App/Listeners/SetCurrentTeamId.php @@ -2,7 +2,6 @@ namespace App\Listeners; -use App\Models\Team; use Filament\Events\TenantSet; use Laravel\Jetstream\Features; From a94dab401ce0f784e1d8c8483a8344fd70dddff9 Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Tue, 14 May 2024 12:40:27 +0100 Subject: [PATCH 5/7] clean up --- stubs/App/Listeners/SetCurrentTeamId.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stubs/App/Listeners/SetCurrentTeamId.php b/stubs/App/Listeners/SetCurrentTeamId.php index 2ddeb1e..76c1ead 100644 --- a/stubs/App/Listeners/SetCurrentTeamId.php +++ b/stubs/App/Listeners/SetCurrentTeamId.php @@ -22,7 +22,10 @@ public function handle(TenantSet $event): void { if (Features::hasTeamFeatures()) { $user = $event->getUser(); - $user->switchTeam($event->getTenant()); + + $team = $event->getTenant(); + + $user->switchTeam($team); } } } From c1cfb560be0840b294f53046f62887db8c66556a Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Tue, 14 May 2024 12:41:29 +0100 Subject: [PATCH 6/7] clean up --- stubs/App/Providers/Filament/AppPanelProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/App/Providers/Filament/AppPanelProvider.php b/stubs/App/Providers/Filament/AppPanelProvider.php index f00d9b7..fd7e617 100644 --- a/stubs/App/Providers/Filament/AppPanelProvider.php +++ b/stubs/App/Providers/Filament/AppPanelProvider.php @@ -7,7 +7,7 @@ use App\Filament\Pages\EditProfile; use App\Filament\Pages\EditTeam; use App\Listeners\CreatePersonalTeam; -use App\Listeners\SetCurrentTeamId; +use App\Listeners\SwitchTeam; use App\Models\Team; use Filament\Events\Auth\Registered; use Filament\Events\TenantSet; @@ -138,7 +138,7 @@ public function boot() */ Event::listen( TenantSet::class, - SetCurrentTeamId::class, + SwitchTeam::class, ); } From b7cc1f148c9d17ab7d467724805b3f0f7d9bbc3d Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Tue, 14 May 2024 12:41:59 +0100 Subject: [PATCH 7/7] clean up --- stubs/App/Listeners/{SetCurrentTeamId.php => SwitchTeam.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename stubs/App/Listeners/{SetCurrentTeamId.php => SwitchTeam.php} (95%) diff --git a/stubs/App/Listeners/SetCurrentTeamId.php b/stubs/App/Listeners/SwitchTeam.php similarity index 95% rename from stubs/App/Listeners/SetCurrentTeamId.php rename to stubs/App/Listeners/SwitchTeam.php index 76c1ead..82dc551 100644 --- a/stubs/App/Listeners/SetCurrentTeamId.php +++ b/stubs/App/Listeners/SwitchTeam.php @@ -5,7 +5,7 @@ use Filament\Events\TenantSet; use Laravel\Jetstream\Features; -class SetCurrentTeamId +class SwitchTeam { /** * Create the event listener.