Skip to content

Commit

Permalink
Configure new App Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Jul 1, 2024
1 parent 9e46c24 commit a542036
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app/Filament/App/Pages/CreateTeam.php
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';
}
}
61 changes: 61 additions & 0 deletions app/Filament/App/Pages/EditProfile.php
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',
];
}
}
64 changes: 64 additions & 0 deletions app/Filament/App/Pages/EditTeam.php
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();
}
}
47 changes: 47 additions & 0 deletions app/Filament/App/Pages/PersonalAccessTokensPage.php
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;
}
}
70 changes: 70 additions & 0 deletions app/Filament/App/Pages/UpdateProfileInformationPage.php
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');
}
}

0 comments on commit a542036

Please sign in to comment.