Skip to content

Commit 4bedb12

Browse files
Only show "Change Teams" options if multiple teams are available (#1294)
* Add conditional logic to only show "Change Teams" option if more than one team exists for user. * Update navigation-menu.blade.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 321f87d commit 4bedb12

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

stubs/inertia/resources/js/Layouts/AppLayout.vue

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,27 @@ const logout = () => {
8787
Create New Team
8888
</DropdownLink>
8989

90-
<div class="border-t border-gray-200 dark:border-gray-600" />
91-
9290
<!-- Team Switcher -->
93-
<div class="block px-4 py-2 text-xs text-gray-400">
94-
Switch Teams
95-
</div>
96-
97-
<template v-for="team in $page.props.auth.user.all_teams" :key="team.id">
98-
<form @submit.prevent="switchToTeam(team)">
99-
<DropdownLink as="button">
100-
<div class="flex items-center">
101-
<svg v-if="team.id == $page.props.auth.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
102-
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
103-
</svg>
104-
105-
<div>{{ team.name }}</div>
106-
</div>
107-
</DropdownLink>
108-
</form>
91+
<template v-if="$page.props.auth.user.all_teams.length > 1">
92+
<div class="border-t border-gray-200 dark:border-gray-600" />
93+
94+
<div class="block px-4 py-2 text-xs text-gray-400">
95+
Switch Teams
96+
</div>
97+
98+
<template v-for="team in $page.props.auth.user.all_teams" :key="team.id">
99+
<form @submit.prevent="switchToTeam(team)">
100+
<DropdownLink as="button">
101+
<div class="flex items-center">
102+
<svg v-if="team.id == $page.props.auth.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
103+
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
104+
</svg>
105+
106+
<div>{{ team.name }}</div>
107+
</div>
108+
</DropdownLink>
109+
</form>
110+
</template>
109111
</template>
110112
</template>
111113
</div>
@@ -246,24 +248,26 @@ const logout = () => {
246248
Create New Team
247249
</ResponsiveNavLink>
248250

249-
<div class="border-t border-gray-200 dark:border-gray-600" />
250-
251251
<!-- Team Switcher -->
252-
<div class="block px-4 py-2 text-xs text-gray-400">
253-
Switch Teams
254-
</div>
255-
256-
<template v-for="team in $page.props.auth.user.all_teams" :key="team.id">
257-
<form @submit.prevent="switchToTeam(team)">
258-
<ResponsiveNavLink as="button">
259-
<div class="flex items-center">
260-
<svg v-if="team.id == $page.props.auth.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
261-
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
262-
</svg>
263-
<div>{{ team.name }}</div>
264-
</div>
265-
</ResponsiveNavLink>
266-
</form>
252+
<template v-if="$page.props.auth.user.all_teams.length > 1">
253+
<div class="border-t border-gray-200 dark:border-gray-600" />
254+
255+
<div class="block px-4 py-2 text-xs text-gray-400">
256+
Switch Teams
257+
</div>
258+
259+
<template v-for="team in $page.props.auth.user.all_teams" :key="team.id">
260+
<form @submit.prevent="switchToTeam(team)">
261+
<ResponsiveNavLink as="button">
262+
<div class="flex items-center">
263+
<svg v-if="team.id == $page.props.auth.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
264+
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
265+
</svg>
266+
<div>{{ team.name }}</div>
267+
</div>
268+
</ResponsiveNavLink>
269+
</form>
270+
</template>
267271
</template>
268272
</template>
269273
</div>

stubs/livewire/resources/views/navigation-menu.blade.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@
5353
</x-dropdown-link>
5454
@endcan
5555

56-
<div class="border-t border-gray-200 dark:border-gray-600"></div>
57-
5856
<!-- Team Switcher -->
59-
<div class="block px-4 py-2 text-xs text-gray-400">
60-
{{ __('Switch Teams') }}
61-
</div>
57+
@if (Auth::user()->allTeams()->count() > 1)
58+
<div class="border-t border-gray-200 dark:border-gray-600"></div>
6259

63-
@foreach (Auth::user()->allTeams() as $team)
64-
<x-switchable-team :team="$team" />
65-
@endforeach
60+
<div class="block px-4 py-2 text-xs text-gray-400">
61+
{{ __('Switch Teams') }}
62+
</div>
63+
64+
@foreach (Auth::user()->allTeams() as $team)
65+
<x-switchable-team :team="$team" />
66+
@endforeach
67+
@endif
6668
</div>
6769
</x-slot>
6870
</x-dropdown>
@@ -198,16 +200,18 @@
198200
</x-responsive-nav-link>
199201
@endcan
200202

201-
<div class="border-t border-gray-200 dark:border-gray-600"></div>
202-
203203
<!-- Team Switcher -->
204-
<div class="block px-4 py-2 text-xs text-gray-400">
205-
{{ __('Switch Teams') }}
206-
</div>
204+
@if (Auth::user()->allTeams()->count() > 1)
205+
<div class="border-t border-gray-200 dark:border-gray-600"></div>
206+
207+
<div class="block px-4 py-2 text-xs text-gray-400">
208+
{{ __('Switch Teams') }}
209+
</div>
207210

208-
@foreach (Auth::user()->allTeams() as $team)
209-
<x-switchable-team :team="$team" component="responsive-nav-link" />
210-
@endforeach
211+
@foreach (Auth::user()->allTeams() as $team)
212+
<x-switchable-team :team="$team" component="responsive-nav-link" />
213+
@endforeach
214+
@endif
211215
@endif
212216
</div>
213217
</div>

0 commit comments

Comments
 (0)