generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Team Switcher at the top right corner of the portal
- Users with more than one team set can switch companies - Users with only one company will simply have the team display on their header
- Loading branch information
1 parent
6799a7b
commit 9d58df3
Showing
15 changed files
with
211 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
@if(auth()->user()?->teams?->count()) | ||
<x-filament::modal> | ||
<x-slot name="trigger"> | ||
<x-filament::button icon="heroicon-s-chevron-double-down" icon-position="after"> | ||
{{auth()->user()->team?->name ?? 'No Company Set'}}: SWITCH | ||
</x-filament::button> | ||
</x-slot> | ||
|
||
<livewire:savannabits-saas::switch-team/> | ||
</x-filament::modal> | ||
@else | ||
<div class="font-black text-sm"> | ||
{{ auth()->user()->team?->name ?: 'No Company Selected' }} | ||
</div> | ||
@endif |
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
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
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,74 @@ | ||
<?php | ||
|
||
namespace Savannabits\Saas\Filament\Resources; | ||
|
||
use Savannabits\Sass\Filament\Resources\TeamResource\RelationManagers; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Savannabits\Saas\Custom\Filament\Columns\ActiveStatusColumn; | ||
use Savannabits\Saas\Models\Team; | ||
|
||
class TeamResource extends Resource | ||
{ | ||
protected static ?string $model = Team::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-building-office-2'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('code') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\Toggle::make('is_active') | ||
->required(), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('code') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(), | ||
ActiveStatusColumn::make(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => \Savannabits\Saas\Filament\Resources\TeamResource\Pages\ManageTeams::route('/'), | ||
]; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace Savannabits\Saas\Filament\Resources\TeamResource\Pages; | ||
|
||
use Filament\Actions; | ||
use Filament\Resources\Pages\ManageRecords; | ||
use Savannabits\Saas\Filament\Resources\TeamResource; | ||
|
||
class ManageTeams extends ManageRecords | ||
{ | ||
protected static string $resource = TeamResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
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 Savannabits\Saas\Livewire; | ||
|
||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Filament\Forms\Form; | ||
use Filament\Pages\Concerns\InteractsWithFormActions; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
use Savannabits\Saas\Models\User; | ||
|
||
class SwitchTeam extends Component implements HasForms | ||
{ | ||
use InteractsWithForms; | ||
use InteractsWithFormActions; | ||
public ?array $data = []; | ||
|
||
public function mount(): void | ||
{ | ||
$this->form->fill(); | ||
} | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Select::make('team_id') | ||
->label('Select Team/Company') | ||
->options(fn() => filament()->auth()->user()->teams()->pluck('name','id')) | ||
->searchable() | ||
->default(filament()->auth()->user()->team?->id) | ||
->required(), | ||
]) | ||
->statePath('data'); | ||
} | ||
|
||
public function create(): void | ||
{ | ||
$data = $this->form->getState(); | ||
User::find(Auth::id())->updateQuietly(['team_id' => $data['team_id']]); | ||
|
||
$this->redirect(request()->header('Referer')); | ||
} | ||
|
||
public function render(): string | ||
{ | ||
return <<<'blade' | ||
<div> | ||
<form wire:submit="create"> | ||
{{ $this->form }} | ||
<x-filament::button class="mt-4 w-full" icon="heroicon-o-building-office-2" type="submit"> | ||
SUBMIT | ||
</x-filament::button> | ||
</form> | ||
<x-filament-actions::modals /> | ||
</div> | ||
blade; | ||
} | ||
} |
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
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,17 @@ | ||
<?php | ||
|
||
namespace Savannabits\Saas\Policies; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
use Savannabits\Saas\Concerns\Policy\InheritsStandardPolicy; | ||
use Savannabits\Saas\Filament\Resources\TeamResource; | ||
|
||
class TeamPolicy | ||
{ | ||
use HandlesAuthorization, InheritsStandardPolicy; | ||
|
||
function getResourceClass(): string | ||
{ | ||
return TeamResource::class; | ||
} | ||
} |
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
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
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
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
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
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