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

Allow personal teams to be optional #910

Closed
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
2 changes: 1 addition & 1 deletion config/jetstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// Features::termsAndPrivacyPolicy(),
// Features::profilePhotos(),
// Features::api(),
// Features::teams(['invitations' => true]),
// Features::teams(['personal' => true, 'invitations' => true]),
Features::accountDeletion(),
],

Expand Down
3 changes: 2 additions & 1 deletion database/factories/TeamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Laravel\Jetstream\Features;

class TeamFactory extends Factory
{
Expand All @@ -25,7 +26,7 @@ public function definition()
return [
'name' => $this->faker->unique()->company(),
'user_id' => User::factory(),
'personal_team' => true,
'personal_team' => Features::createsPersonalTeam(),
];
}
}
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function withPersonalTeam()
return $this->has(
Team::factory()
->state(function (array $attributes, User $user) {
return ['name' => $user->name.'\'s Team', 'user_id' => $user->id, 'personal_team' => true];
return ['name' => $user->name.'\'s Team', 'user_id' => $user->id, 'personal_team' => Features::createsPersonalTeam()];
}),
'ownedTeams'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ protected function ensureApplicationIsTeamCompatible()
$this->callSilent('vendor:publish', ['--tag' => 'jetstream-team-migrations', '--force' => true]);

// Configuration...
$this->replaceInFile('// Features::teams([\'invitations\' => true])', 'Features::teams([\'invitations\' => true])', config_path('jetstream.php'));
$this->replaceInFile('// Features::teams([\'personal\' => true, \'invitations\' => true])', 'Features::teams([\'personal\' => true, \'invitations\' => true])', config_path('jetstream.php'));

// Directories...
(new Filesystem)->ensureDirectoryExists(app_path('Actions/Jetstream'));
Expand Down
10 changes: 10 additions & 0 deletions src/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public static function hasTeamFeatures()
return static::enabled(static::teams());
}

/**
* Determine if a personal team is created on user registration.
*
* @return bool
*/
public static function createsPersonalTeam()
{
return static::optionEnabled(static::teams(), 'personal');
}

/**
* Determine if invitations are sent to team members.
*
Expand Down
3 changes: 2 additions & 1 deletion src/HasTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Jetstream;

use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Sanctum\HasApiTokens;

trait HasTeams
Expand Down Expand Up @@ -93,7 +94,7 @@ public function teams()
*/
public function personalTeam()
{
return $this->ownedTeams->where('personal_team', true)->first();
return $this->ownedTeams->where('personal_team', Features::createsPersonalTeam())->first();
}

/**
Expand Down
13 changes: 8 additions & 5 deletions stubs/app/Actions/Fortify/CreateNewUserWithTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Jetstream;

class CreateNewUser implements CreatesNewUsers
Expand Down Expand Up @@ -48,10 +49,12 @@ public function create(array $input)
*/
protected function createTeam(User $user)
{
$user->ownedTeams()->save(Team::forceCreate([
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]));
if (Features::createsPersonalTeam()) {
$user->ownedTeams()->save(Team::forceCreate([
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]));
}
}
}
76 changes: 45 additions & 31 deletions stubs/inertia/resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

<div class="hidden sm:flex sm:items-center sm:ml-6">
<div class="ml-3 relative">
<div class="ml-3 relative" v-if="$page.props.user.current_team">
<!-- Teams Dropdown -->
<jet-dropdown align="right" width="60" v-if="$page.props.jetstream.hasTeamFeatures">
<template #trigger>
Expand Down Expand Up @@ -81,6 +81,12 @@
</jet-dropdown>
</div>

<div class="ml-3 relative" v-if="!$page.props.user.current_team && $page.props.jetstream.canCreateTeams">
<Link :href="route('teams.create')" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition">
Create New Team
</Link>
</div>

<!-- Settings Dropdown -->
<div class="ml-3 relative">
<jet-dropdown align="right" width="48">
Expand Down Expand Up @@ -178,37 +184,45 @@

<!-- Team Management -->
<template v-if="$page.props.jetstream.hasTeamFeatures">
<div class="border-t border-gray-200"></div>

<div class="block px-4 py-2 text-xs text-gray-400">
Manage Team
</div>

<!-- Team Settings -->
<jet-responsive-nav-link :href="route('teams.show', $page.props.user.current_team)" :active="route().current('teams.show')">
Team Settings
</jet-responsive-nav-link>

<jet-responsive-nav-link :href="route('teams.create')" :active="route().current('teams.create')" v-if="$page.props.jetstream.canCreateTeams">
Create New Team
</jet-responsive-nav-link>
<template v-if="$page.props.user.current_team">
<div class="border-t border-gray-200"></div>

<div class="block px-4 py-2 text-xs text-gray-400">
Manage Team
</div>

<!-- Team Settings -->
<jet-responsive-nav-link :href="route('teams.show', $page.props.user.current_team)" :active="route().current('teams.show')">
Team Settings
</jet-responsive-nav-link>

<jet-responsive-nav-link :href="route('teams.create')" :active="route().current('teams.create')" v-if="$page.props.jetstream.canCreateTeams">
Create New Team
</jet-responsive-nav-link>

<div class="border-t border-gray-200"></div>

<!-- Team Switcher -->
<div class="block px-4 py-2 text-xs text-gray-400">
Switch Teams
</div>

<template v-for="team in $page.props.user.all_teams" :key="team.id">
<form @submit.prevent="switchToTeam(team)">
<jet-responsive-nav-link as="button">
<div class="flex items-center">
<svg v-if="team.id == $page.props.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24"><path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<div>{{ team.name }}</div>
</div>
</jet-responsive-nav-link>
</form>
</template>
</template>

<div class="border-t border-gray-200"></div>

<!-- Team Switcher -->
<div class="block px-4 py-2 text-xs text-gray-400">
Switch Teams
</div>

<template v-for="team in $page.props.user.all_teams" :key="team.id">
<form @submit.prevent="switchToTeam(team)">
<jet-responsive-nav-link as="button">
<div class="flex items-center">
<svg v-if="team.id == $page.props.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24"><path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<div>{{ team.name }}</div>
</div>
</jet-responsive-nav-link>
</form>
<template v-else>
<jet-responsive-nav-link :href="route('teams.create')" :active="route().current('teams.create')" v-if="$page.props.jetstream.canCreateTeams">
Create New Team
</jet-responsive-nav-link>
</template>
</template>
</div>
Expand Down
Loading