Skip to content

Commit

Permalink
Upgrade composer and npm
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Jul 20, 2024
1 parent e5f870e commit 774e1ff
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
35 changes: 28 additions & 7 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Actions\Fortify;

use App\Models\Team;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
Expand All @@ -15,12 +17,12 @@ class CreateNewUser implements CreatesNewUsers
/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
Expand All @@ -31,10 +33,29 @@ public function create(array $input): User
'password' => $this->passwordRules(),
])->validate();

return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
return DB::transaction(function () use ($input) {
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]), function (User $user) {
$team = $this->createTeam($user);
$user->switchTeam($team);
setPermissionsTeamId($team->id);
$user->assignRole('free');
});
});
}

/**
* Create a personal team for the user.
*/
protected function createTeam(User $user)
{
return $user->ownedTeams()->save(Team::forceCreate([
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]));
}
}
2 changes: 1 addition & 1 deletion app/Actions/Fortify/CreateNewUserWithTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Jetstream;

class CreateNewUser implements CreatesNewUsers
class CreateNewUserWithTeams implements CreatesNewUsers
{
use PasswordValidationRules;

Expand Down
4 changes: 2 additions & 2 deletions app/Filament/App/Pages/CreateTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Filament\App\Pages;

use App\Models\Team;
use App\Models\User;
use Filament\Facades\Filament;
use Filament\Forms\Components\TextInput;
use Filament\Pages\Tenancy\RegisterTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class CreateTeam extends RegisterTenant
Expand All @@ -32,7 +32,7 @@ protected function getFormSchema(): array
];
}

protected function handleRegistration(array $data): Team
protected function handleRegistration(array $data): Model
{
return app(\App\Actions\Jetstream\CreateTeam::class)->create(auth()->user(), $data);
}
Expand Down
7 changes: 5 additions & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

'url' => env('APP_URL', 'http://localhost'),

'asset_url' => env('ASSET_URL'),
'asset_url' => env('ASSET_URL', '/'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -160,7 +160,6 @@
* Package Service Providers...
*/
JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class,
JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class,

/*
* Application Service Providers...
Expand All @@ -172,6 +171,10 @@
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\Filament\AppPanelProvider::class,
App\Providers\RouteServiceProvider::class,

App\Providers\TeamServiceProvider::class,
App\Providers\JetstreamServiceProvider::class,
App\Providers\FortifyServiceProvider::class,
])->toArray(),

/*
Expand Down
2 changes: 1 addition & 1 deletion config/jetstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// Features::termsAndPrivacyPolicy(),
// Features::profilePhotos(),
// Features::api(),
// Features::teams(['invitations' => true]),
Features::teams(['invitations' => true]),
Features::accountDeletion(),
],

Expand Down

0 comments on commit 774e1ff

Please sign in to comment.