Optimierung 5.2 (Teil 1): ProvidesUserFormRules-Concern

Die zwischen Benutzer-Anlegen und -Bearbeiten identischen Validierungsbloecke
liegen jetzt in ProvidesUserFormRules: userIdentityRules(?int $ignore) (E-Mail-
Unique ignoriert beim Bearbeiten den eigenen Datensatz), userRolesAndCompaniesRules()
und userBillingRules(). Beide Formulare nutzen die Array-Spreads; die nur im
Bearbeiten genutzten Profil-/Kontakt-Regeln bleiben dort inline. Ungenutzten
Rule-Import aus dem Anlegen-Formular entfernt.

Offen (mit User abzustimmen, UI-/Divergenz-lastig): gemeinsamer Save-Service und
die Blade-Feld-Components.

31 User-Tests gruen.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 12:41:57 +00:00
parent a8958c176e
commit 89842ac37f
4 changed files with 83 additions and 40 deletions

View file

@ -17,6 +17,7 @@ use Spatie\Permission\Models\Role;
new #[Layout('components.layouts.app'), Title('Benutzer bearbeiten')] class extends Component
{
use \App\Livewire\Concerns\HasFullTextSearch;
use \App\Livewire\Concerns\ProvidesUserFormRules;
#[Locked]
public int $id;
@ -376,11 +377,7 @@ new #[Layout('components.layouts.app'), Title('Benutzer bearbeiten')] class exte
public function save(): void
{
$validated = $this->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', Rule::unique('users', 'email')->ignore($this->id)],
'portal' => ['required', Rule::in(array_map(static fn (Portal $portal): string => $portal->value, Portal::cases()))],
'registrationType' => ['required', Rule::in(array_map(static fn (RegistrationType $type): string => $type->value, RegistrationType::cases()))],
'language' => ['required', 'string', Rule::in(['de', 'en'])],
...$this->userIdentityRules($this->id),
'profile.salutation_key' => ['nullable', 'string', 'max:20'],
'profile.title' => ['nullable', 'string', 'max:80'],
'profile.first_name' => ['nullable', 'string', 'max:80'],
@ -397,12 +394,7 @@ new #[Layout('components.layouts.app'), Title('Benutzer bearbeiten')] class exte
'profile.tax_exempt' => ['boolean'],
'profile.tax_exempt_reason' => ['nullable', 'string', 'max:1000'],
'profile.disable_footer_code' => ['boolean'],
'selectedRoles' => ['required', 'array', 'min:1'],
'selectedRoles.*' => ['string', Rule::exists('roles', 'name')],
'linkedCompanyIds' => ['array'],
'linkedCompanyIds.*' => ['integer', Rule::exists('companies', 'id')],
'companyRoles' => ['array'],
'companyRoles.*' => ['string', Rule::in(['member', 'responsible', 'owner'])],
...$this->userRolesAndCompaniesRules(),
'contactForms' => ['array'],
'contactForms.*.id' => ['required', 'integer', Rule::exists('contacts', 'id')],
'contactForms.*.company_id' => ['required', 'integer', Rule::exists('companies', 'id')],
@ -411,14 +403,7 @@ new #[Layout('components.layouts.app'), Title('Benutzer bearbeiten')] class exte
'contactForms.*.email' => ['nullable', 'email', 'max:255'],
'contactForms.*.phone' => ['nullable', 'string', 'max:40'],
'contactForms.*.responsibility' => ['nullable', 'string', 'max:255'],
'billing.salutation_key' => ['nullable', 'string', 'max:20'],
'billing.title' => ['nullable', 'string', 'max:80'],
'billing.name' => ['nullable', 'string', 'max:255'],
'billing.address1' => ['nullable', 'string', 'max:255'],
'billing.address2' => ['nullable', 'string', 'max:255'],
'billing.postal_code' => ['nullable', 'string', 'max:20'],
'billing.city' => ['nullable', 'string', 'max:120'],
'billing.country_code' => ['nullable', 'string', 'size:2'],
...$this->userBillingRules(),
]);
$user = User::query()->findOrFail($this->id);