Skip to content

Commit

Permalink
Merge pull request #68 from openfoodfoundation/feature/easy-team-switch
Browse files Browse the repository at this point in the history
Feature: Easy Team Switch
  • Loading branch information
ok200paul authored Oct 22, 2024
2 parents ec5e1a6 + d2e30c8 commit 338f99f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
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

0 comments on commit 338f99f

Please sign in to comment.