From 02b6c2291b3ffabaa3a973a97eafe9f059f80ddc Mon Sep 17 00:00:00 2001 From: Paul Grimes Date: Tue, 22 Oct 2024 15:34:08 +1100 Subject: [PATCH 1/2] Feature: Easy Team Switch --- app/Http/Middleware/HandleInertiaRequests.php | 11 +++++--- resources/js/Layouts/AuthenticatedLayout.vue | 25 ++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 86abc7e2..5e5da7e7 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -6,6 +6,8 @@ use App\Enums\VoucherSetType; use App\Models\Country; use App\Models\Team; +use App\Models\TeamUser; +use Auth; use Illuminate\Http\Request; use Inertia\Middleware; @@ -41,10 +43,11 @@ public function share(Request $request): array return [ ...parent::share($request), - 'auth' => [ - 'user' => $request->user(), - 'currentTeam' => $team, - 'teamCountry' => Country::find($team?->country_id), + 'auth' => [ + 'user' => $request->user(), + 'currentTeam' => $team, + 'availableTeams' => TeamUser::with('team')->where('user_id', Auth::id())->get(), + 'teamCountry' => Country::find($team?->country_id), ], 'personalAccessTokenAbilities' => PersonalAccessTokenAbility::groupsAbilityCasesWithDefinitions(), 'platformAppTokenAbilities' => PersonalAccessTokenAbility::platformAppTokenAbilities(), diff --git a/resources/js/Layouts/AuthenticatedLayout.vue b/resources/js/Layouts/AuthenticatedLayout.vue index 599ada16..c7d28caa 100644 --- a/resources/js/Layouts/AuthenticatedLayout.vue +++ b/resources/js/Layouts/AuthenticatedLayout.vue @@ -5,7 +5,7 @@ import Dropdown from '@/Components/Dropdown.vue'; import DropdownLink from '@/Components/DropdownLink.vue'; import NavLink from '@/Components/NavLink.vue'; import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue'; -import {Link} from '@inertiajs/vue3'; +import {Link, usePage} from '@inertiajs/vue3'; import PrimaryButton from "@/Components/PrimaryButton.vue"; import SearchComponent from "@/Components/App/Search/SearchComponent.vue"; @@ -13,6 +13,8 @@ const showingNavigationDropdown = ref(false);