-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b6b29b
commit b4560ed
Showing
5 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Filament\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\Support\Facades\Auth; | ||
|
||
class CreateTeam extends RegisterTenant | ||
{ | ||
protected static string $view = 'filament.pages.create-team'; | ||
|
||
public $name = ''; | ||
|
||
protected ?string $maxWidth = '2xl'; | ||
|
||
public function mount(): void | ||
{ | ||
// abort_unless(Filament::auth()->user()->canCreateTeams(), 403); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
TextInput::make('name') | ||
->label('Team Name') | ||
->required() | ||
->maxLength(255), | ||
]; | ||
} | ||
|
||
protected function handleRegistration(array $data): Team | ||
{ | ||
return app(\App\Actions\Jetstream\CreateTeam::class)->create(auth()->user(), $data); | ||
} | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
return [ | ||
url()->current() => 'Create Team', | ||
]; | ||
} | ||
|
||
public static function getLabel(): string | ||
{ | ||
return 'Create Team'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use App\Models\User; | ||
use Filament\Facades\Filament; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Pages\Page; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class EditProfile extends Page | ||
{ | ||
protected static string $view = 'filament.pages.edit-profile'; | ||
protected static ?string $navigationIcon = 'heroicon-o-chart-bar'; | ||
|
||
public User $user; | ||
|
||
public function mount() | ||
{ | ||
$this->user = Auth::user(); | ||
$this->form->fill([ | ||
'name' => $this->user->name, | ||
'email' => $this->user->email, | ||
]); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
TextInput::make('name') | ||
->label('Name') | ||
->required() | ||
->maxLength(255), | ||
TextInput::make('email') | ||
->label('Email Address') | ||
->required() | ||
->maxLength(255), | ||
]; | ||
} | ||
|
||
public function submit() | ||
{ | ||
$this->validate(); | ||
|
||
$state = $this->form->getState(); | ||
|
||
$this->user->forceFill([ | ||
'name' => $state['name'], | ||
'email' => $state['email'], | ||
])->save(); | ||
|
||
Filament::notify('success', 'Your profile has been updated.'); | ||
} | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
return [ | ||
url()->current() => 'Edit Profile', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
use Filament\Facades\Filament; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Pages\Tenancy\EditTenantProfile; | ||
|
||
class EditTeam extends EditTenantProfile | ||
{ | ||
protected static string $view = 'filament.pages.edit-team'; | ||
|
||
public $name = ''; | ||
|
||
public static function getLabel(): string | ||
{ | ||
return 'Edit Team'; | ||
} | ||
|
||
public function mount(): void | ||
{ | ||
abort_unless($this->user()->canCreateTeams(), 403); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
TextInput::make('name') | ||
->label('Team Name') | ||
->required() | ||
->maxLength(255), | ||
]; | ||
} | ||
|
||
public function submit() | ||
{ | ||
$this->validate(); | ||
|
||
$team = Team::forceCreate([ | ||
'user_id' => Filament::auth()->id(), | ||
'name' => $this->name, | ||
'personal_team' => false, | ||
]); | ||
|
||
$this->user()->teams()->attach($team, ['role' => 'admin']); | ||
$this->user()->switchTeam($team); | ||
|
||
return redirect()->route('filament.pages.edit-team', ['team' => $team]); | ||
} | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
return [ | ||
url()->current() => 'Create Team', | ||
]; | ||
} | ||
|
||
private function user(): User | ||
{ | ||
return Filament::auth()->user(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use App\Models\User; | ||
use Filament\Pages\Page; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class PersonalAccessTokensPage extends Page | ||
{ | ||
protected static string $view = 'filament.pages.profile.personal-access-tokens'; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-key'; | ||
|
||
protected static ?string $navigationGroup = 'Account'; | ||
|
||
protected static ?int $navigationSort = 3; | ||
|
||
protected static ?string $title = 'Personal Access Tokens'; | ||
|
||
public User $user; | ||
|
||
public function mount(): void | ||
{ | ||
$this->user = Auth::user(); | ||
} | ||
|
||
public function createApiToken(string $name): void | ||
{ | ||
$this->user->createToken($name); | ||
} | ||
|
||
public function deleteApiToken(string $name): void | ||
{ | ||
$this->user->tokens()->where('name', $name)->first()->delete(); | ||
} | ||
|
||
public function getHeading(): string | ||
{ | ||
return static::$title; | ||
} | ||
|
||
public static function shouldRegisterNavigation(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use Filament\Forms\Components\TextInput; | ||
use Filament\Pages\Page; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class UpdateProfileInformationPage extends Page | ||
{ | ||
protected static string $view = 'filament.pages.profile.update-profile-information'; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-user'; | ||
|
||
protected static ?string $navigationGroup = 'Account'; | ||
|
||
protected static ?int $navigationSort = 0; | ||
|
||
protected static ?string $title = 'Profile'; | ||
|
||
public $name; | ||
|
||
public $email; | ||
|
||
public function mount(): void | ||
{ | ||
$this->form->fill([ | ||
'name' => Auth::user()->name, | ||
'email' => Auth::user()->email, | ||
]); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
TextInput::make('name') | ||
->label('Name') | ||
->required(), | ||
TextInput::make('email') | ||
->label('Email Address') | ||
->required(), | ||
]; | ||
} | ||
|
||
public function submit(): void | ||
{ | ||
$this->form->getState(); | ||
|
||
$state = array_filter([ | ||
'name' => $this->name, | ||
'email' => $this->email, | ||
]); | ||
|
||
$user = Auth::user(); | ||
|
||
$user->forceFill($state)->save(); | ||
|
||
session()->flash('status', 'Your profile has been updated.'); | ||
} | ||
|
||
public function getHeading(): string | ||
{ | ||
return static::$title; | ||
} | ||
|
||
public static function shouldRegisterNavigation(): bool | ||
{ | ||
return true; //config('filament-jetstream.show_update_profile_information_page'); | ||
} | ||
} |