register form

This commit is contained in:
salam committed 2025-09-20 16:26:01 +02:00
1 parent 390a98e961
commit b5d090cf5e
18 files changed
+349 -46

No files matched your search

+200
View File
@@ -0,0 +1,200 @@
<?php
namespace App\Filament\Pages\Auth;
use App\Models\Konto;
use Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber;
use Filament\Auth\Pages\Register as BaseRegister;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Fieldset;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Wizard;
use Filament\Schemas\Components\Wizard\Step;
use Filament\Schemas\Schema;
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
class Register extends BaseRegister
{
public function form(Schema $schema): Schema
{
return $schema
->components([
Wizard::make([
Step::make('Profile')
->icon('lucide-user-plus')
->description('Benutzer anlegen.')
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
]),
Wizard\Step::make('Konto')
// ->columns(4)
->icon('lucide-key-square')
->description('Mit einem Konto verbinden.')
->schema([
$this->getKontoFormComponent(),
/** OLD */
$this->selectKontoFormComponent(),
/** NEU */
Fieldset::make('Rechnungsdaten')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
$this->getCompanyFormComponent(),
$this->getUIDFormComponent(),
$this->getPlaceFormComponent(),
$this->getPLZFormComponent(),
$this->getCountryFormComponent(),
$this->getAdresseFormComponent(),
$this->getGenderFormComponent(),
$this->getFirstNameFormComponent(),
$this->getLastNameFormComponent(),
$this->getPhoneFormComponent(),
$this->getKontoEmailFormComponent(),
])->columnSpan(4),
]),
]),
]);
}
protected function getPhoneFormComponent(): PhoneInput
{
return PhoneInput::make('phone')
->label('Telefon')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->defaultCountry('AT');
}
protected function getCountryFormComponent(): TextInput
{
return TextInput::make('country')
->label('Land')
->placeholder('Österreich')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getKontoEmailFormComponent(): TextInput
{
return TextInput::make('konto-email')
->label('E-Mail')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getPLZFormComponent(): TextInput
{
return TextInput::make('code')
->label('Postleitzahl')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getPlaceFormComponent(): TextInput
{
return TextInput::make('place')
->label('Ort')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getAdresseFormComponent(): Textarea
{
return Textarea::make('address')
->label('Adresse')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getFirstNameFormComponent(): TextInput
{
return TextInput::make('first_name')
->label('Vorname')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getLastNameFormComponent(): TextInput
{
return TextInput::make('last_name')
->label('Nachname')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getUIDFormComponent(): TextInput
{
return TextInput::make('uid_number')
->label('UID Nummer')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->rules([new VatNumber])
->required();
}
protected function getCompanyFormComponent(): TextInput
{
return TextInput::make('company')
->label('Firma')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getRoleFormComponent(): Select
{
return Select::make('role')
->options([
'gutachter' => 'Gutachter',
'super_admin' => 'Administrator',
])
->default('gutachter')
->required();
}
protected function getGenderFormComponent(): Select
{
return Select::make('gender')
->columnSpan(2)
->label('Geschlecht')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required();
}
protected function getKontoFormComponent(): Select
{
return Select::make('konto')
->columnSpan(4)
->label('Registriermodus')
->prefixIcon('lucide-key-square')
->prefixIconColor('primary')
->aboveLabel([
'Bitte wählen Sie ein bestehendes Konto oder erstellen Sie ein neues. Eine Registrierung bei einem bestehenden Konto muß vom Kontoinhaber bestätigt werden.',
])
->options([
'old' => 'Mit einem bestehenden Konto verbinden',
'new' => 'Ein neues Konto erstellen',
])
->live()
->required();
}
protected function selectKontoFormComponent(): Select
{
return Select::make('konto_id')
->columnSpan(4)
->label('Konto auswählen')
->visible(fn (Get $get): bool => $get('konto') == 'old')
->options(Konto::query()->pluck('company', 'id'))
->searchable()
->required();
}
}
+4
View File
@@ -30,6 +30,7 @@ class User extends Authenticatable implements FilamentUser, HasAppAuthentication
'email',
'konto_id',
'password',
'role',
'super_admin',
'app_verified_at',
'first_name',
@@ -76,6 +77,9 @@ class User extends Authenticatable implements FilamentUser, HasAppAuthentication
{
static::addGlobalScope(new KontoScope);
static::creating(function (User $user) {
$user->role = 'gutachter';
});
}
public function getAppAuthenticationSecret(): ?string
@@ -3,6 +3,7 @@
namespace App\Providers\Filament;
use Agencetwogether\HooksHelper\HooksHelperPlugin;
use App\Filament\Pages\Auth\Register;
use App\Http\Middleware\AppUserVerifiedMiddleware;
use Awcodes\LightSwitch\Enums\Alignment;
use Awcodes\LightSwitch\LightSwitchPlugin;
@@ -16,7 +17,6 @@ use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages\Dashboard;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Support\Enums\Width;
use Filament\View\PanelsRenderHook;
use Filament\Widgets\AccountWidget;
@@ -39,15 +39,12 @@ class AdminPanelProvider extends PanelProvider
->id('admin')
->path('app')
->login()
->registration()
->passwordReset()
->emailVerification()
->emailChangeVerification()
->profile(isSimple: false)
->default()
->colors([
'primary' => Color::Blue,
])
->registration(Register::class)
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => auth()->user()->hasRole('konto_switch') ? Blade::render('@livewire(\'konto-switch\')') : false