From fa17696549f208f094077e795e2a6a484db308d1 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Mon, 1 Jul 2024 02:03:35 +0000 Subject: [PATCH] Configure new App Panel --- app/Filament/App/Pages/CreateTeam.php | 51 ++++++++++++++ app/Filament/App/Pages/EditProfile.php | 61 ++++++++++++++++ app/Filament/App/Pages/EditTeam.php | 64 +++++++++++++++++ .../App/Pages/PersonalAccessTokensPage.php | 47 +++++++++++++ .../Pages/UpdateProfileInformationPage.php | 70 +++++++++++++++++++ 5 files changed, 293 insertions(+) create mode 100644 app/Filament/App/Pages/CreateTeam.php create mode 100644 app/Filament/App/Pages/EditProfile.php create mode 100644 app/Filament/App/Pages/EditTeam.php create mode 100644 app/Filament/App/Pages/PersonalAccessTokensPage.php create mode 100644 app/Filament/App/Pages/UpdateProfileInformationPage.php diff --git a/app/Filament/App/Pages/CreateTeam.php b/app/Filament/App/Pages/CreateTeam.php new file mode 100644 index 00000000..4f621858 --- /dev/null +++ b/app/Filament/App/Pages/CreateTeam.php @@ -0,0 +1,51 @@ +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'; + } +} diff --git a/app/Filament/App/Pages/EditProfile.php b/app/Filament/App/Pages/EditProfile.php new file mode 100644 index 00000000..f2dfd941 --- /dev/null +++ b/app/Filament/App/Pages/EditProfile.php @@ -0,0 +1,61 @@ +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', + ]; + } +} diff --git a/app/Filament/App/Pages/EditTeam.php b/app/Filament/App/Pages/EditTeam.php new file mode 100644 index 00000000..27cb94ee --- /dev/null +++ b/app/Filament/App/Pages/EditTeam.php @@ -0,0 +1,64 @@ +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(); + } +} diff --git a/app/Filament/App/Pages/PersonalAccessTokensPage.php b/app/Filament/App/Pages/PersonalAccessTokensPage.php new file mode 100644 index 00000000..44f153dc --- /dev/null +++ b/app/Filament/App/Pages/PersonalAccessTokensPage.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/app/Filament/App/Pages/UpdateProfileInformationPage.php b/app/Filament/App/Pages/UpdateProfileInformationPage.php new file mode 100644 index 00000000..627c0618 --- /dev/null +++ b/app/Filament/App/Pages/UpdateProfileInformationPage.php @@ -0,0 +1,70 @@ +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'); + } +}