refactoring into clusters

This commit is contained in:
salam committed 2026-05-13 10:10:48 +02:00
1 parent 042a5a8b58
commit 48deb69379
97 files changed
+186 -198

No files matched your search

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users\Pages;
use App\Filament\Clusters\Verwaltung\Users\UserResource;
use Filament\Resources\Pages\CreateRecord;
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}
@@ -0,0 +1,23 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users\Pages;
use App\Filament\Clusters\Verwaltung\Users\UserResource;
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Resources\Pages\EditRecord;
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
ForceDeleteAction::make(),
RestoreAction::make(),
];
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users\Pages;
use App\Filament\Clusters\Verwaltung\Users\UserResource;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\Section;
class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('inviteUser')
->label('Einladen')
->icon('phosphor-envelope')
->form([
Section::make('Jemanden einladen')
->icon('lucide-user')
->description('Nur mit dieser Einladung können sich weitere Benutzer bei diesem Konto registrieren.')
->schema([
TextInput::make('email')
->label('E-Mail')
->prefixIcon('phosphor-envelope')
->email()
->required()
->belowContent('Die Einladung ist 12 Stunden gültig.'),
]),
])
->action(function ($data) {
$invitation = Invitation::create([
'knoto_id' => auth()->user()->konto_id,
'email' => $data['email'],
]);
// @todo Add email sending here
Notification::make('invitedSuccess')
->body('Der Benutzer wurde erfolgreich eingelanden!')
->success()->send();
}),
CreateAction::make()
->icon('phosphor-file-plus')
->createAnother(false)
->mutateDataUsing(function (array $data): array {
$data['konto_id'] = auth()->user()->konto_id;
return $data;
}),
];
}
}
@@ -0,0 +1,83 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users\Schemas;
use App\Models\User;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
class UserForm
{
public User $user;
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Benutzerkonto')
->icon('lucide-user')
->schema([
Select::make('gender')
->prefixIcon('phosphor-gender-neuter')
->label('Geschlecht')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required(),
TextInput::make('name')
->prefixIcon('phosphor-user')
->required(),
TextInput::make('email')->email()
->required()
->prefixIcon('phosphor-envelope')
->label('E-Mail'),
TextInput::make('password')
->label('Passwort')
->password()
->revealable()
->prefixIcon('phosphor-lock')
->dehydrated(fn ($state): bool => filled($state))
->dehydrateStateUsing(fn ($state): string => Hash::make($state))
->same('password_confirmation')
->rule(Password::min(8)
->mixedCase()
->numbers()
->symbols()
->uncompromised())
->label('Password'),
TextInput::make('password_confirmation')
->label('Passwort Bestätigen')
->prefixIcon('phosphor-lock')
->password()
->dehydrated(false)
->same('password')
->revealable(),
Checkbox::make('agb_akzeptiert')
->default(false)
->label('Allgemeinen Geschäftsbedinnungen akzeptieren')
->accepted()
->validationMessages([
'accepted' => 'Das Akzeptieren der Allgemeinen Geschäftsbedingungen ist erforderlich.',
]),
Select::make('roles')
->label('Rollen')
->prefixIcon('phosphor-gear')
->aboveContent('Nur für SuperAdmin sichtbare')
->visible(fn () => auth()->user()->hasRole('super_admin'))
->relationship('roles', 'name')
->multiple()
->preload()
->searchable(),
]),
])->columns(1);
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users\Tables;
use Filament\Actions\EditAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
class UsersTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('gender')->label('Geschlecht'),
TextColumn::make('name'),
TextColumn::make('konto.company')->badge()->searchable(),
TextColumn::make('email')->copyable()->label('E-Mail'),
IconColumn::make('agb_akzeptiert')
->searchable()
->label('AGB')
->boolean()
->trueIcon(Heroicon::OutlinedCheckBadge)
->falseIcon(Heroicon::OutlinedXMark),
])
->filters([
TrashedFilter::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
])
->recordActions([
EditAction::make()->iconButton(),
]);
}
}
@@ -0,0 +1,84 @@
<?php
namespace App\Filament\Clusters\Verwaltung\Users;
use App\Filament\Clusters\Verwaltung\Users\Pages\ListUsers;
use App\Filament\Clusters\Verwaltung\Users\Schemas\UserForm;
use App\Filament\Clusters\Verwaltung\Users\Tables\UsersTable;
use App\Filament\Clusters\Verwaltung\VerwaltungCluster;
use App\Models\User;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static ?int $navigationSort = 4;
protected static ?string $cluster = VerwaltungCluster::class;
// protected static bool $shouldSkipAuthorization = true;
protected static string|BackedEnum|null $navigationIcon = 'lucide-user-pen';
protected static ?string $navigationLabel = 'Benutzer';
protected static ?string $modelLabel = 'Benutzer';
protected static ?string $pluralModelLabel = 'Benutzer';
public static function form(Schema $schema): Schema
{
return UserForm::configure($schema);
}
public static function table(Table $table): Table
{
return UsersTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListUsers::route('/'),
];
}
public static function getRecordRouteBindingEloquentQuery(): Builder
{
return parent::getRecordRouteBindingEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
public static function getEloquentQuery(): Builder
{
if (auth()->user()->super_admin) {
return parent::getEloquentQuery()->where('konto_id', auth()->user()->konto_id);
} else {
return parent::getEloquentQuery()->where('super_admin', false)->where('konto_id', auth()->user()->konto_id);
}
}
public static function getNavigationBadge(): ?string
{
if (auth()->user()->super_admin) {
return parent::getEloquentQuery()->where('konto_id', auth()->user()->konto_id)->count();
} else {
return parent::getEloquentQuery()->where('super_admin', false)->where('konto_id', auth()->user()->konto_id)->count();
}
}
}