Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Easy Team Switch #68

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand Down
24 changes: 23 additions & 1 deletion resources/js/Layouts/AuthenticatedLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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";

const showingNavigationDropdown = ref(false);
</script>

<template>

<div>
<div class="min-h-screen bg-gray-100">
<nav class="bg-white border-b border-gray-100">
Expand Down Expand Up @@ -99,6 +100,17 @@ const showingNavigationDropdown = ref(false);
<DropdownLink :href="route('audit-trail')">
Audit Trail
</DropdownLink>

<hr>
<div class="px-4 opacity-50 text-xs mt-4">
Switch team
</div>
<DropdownLink :href="'/switch-team/' + userTeam.team_id" v-for="userTeam in usePage().props.auth.availableTeams">
{{ userTeam.team.name }}
</DropdownLink>
<hr>


<DropdownLink :href="route('logout')" method="post" as="button">
Log Out
</DropdownLink>
Expand Down Expand Up @@ -166,6 +178,16 @@ const showingNavigationDropdown = ref(false);

<div class="mt-3 space-y-1">
<ResponsiveNavLink :href="route('profile.edit')"> Profile </ResponsiveNavLink>

<hr>
<div class="px-4 opacity-50 text-xs mt-4">
Switch team
</div>
<ResponsiveNavLink :href="'/switch-team/' + userTeam.team_id" v-for="userTeam in usePage().props.auth.availableTeams">
{{ userTeam.team.name }}
</ResponsiveNavLink>
<hr>

<ResponsiveNavLink :href="route('logout')" method="post" as="button">
Log Out
</ResponsiveNavLink>
Expand Down
Loading