orderBy('name') ->get(); } public function mount(): void { // Setze default auf die erste einladbare Rolle $firstRole = $this->getPartnerRoles()->first(); $this->roleId = $firstRole?->id; } public function sendInvitation(): void { $availableRoleIds = $this->getPartnerRoles()->pluck('id')->toArray(); $this->validate([ 'companyName' => 'required|string|max:255', 'contactFirstName' => 'nullable|string|max:255', 'contactLastName' => 'nullable|string|max:255', 'roleId' => 'required|exists:roles,id|in:' . implode(',', $availableRoleIds), 'email' => 'required|email|max:255|unique:users,email', 'expiryWeeks' => 'required|integer|in:1,2,3,4', ], [ 'companyName.required' => __('Bitte geben Sie einen Firmennamen ein.'), 'companyName.max' => __('Der Firmenname darf maximal 255 Zeichen lang sein.'), 'contactFirstName.max' => __('Der Vorname darf maximal 255 Zeichen lang sein.'), 'contactLastName.max' => __('Der Nachname darf maximal 255 Zeichen lang sein.'), 'roleId.required' => __('Bitte wählen Sie einen Partner-Typ aus.'), 'roleId.exists' => __('Der gewählte Partner-Typ ist ungültig.'), 'email.required' => __('Bitte geben Sie eine E-Mail-Adresse ein.'), 'email.email' => __('Bitte geben Sie eine gültige E-Mail-Adresse ein.'), 'email.max' => __('Die E-Mail-Adresse darf maximal 255 Zeichen lang sein.'), 'email.unique' => __('Diese E-Mail-Adresse ist bereits als Benutzer registriert.'), 'expiryWeeks.required' => __('Bitte wählen Sie eine Gültigkeitsdauer aus.'), 'expiryWeeks.in' => __('Die Gültigkeitsdauer muss zwischen 1 und 4 Wochen liegen.'), ]); // Prüfe ob bereits eine aktive Einladung existiert $existingInvitation = PartnerInvitation::where('email', $this->email) ->pending() ->first(); if ($existingInvitation) { $this->addError('email', __('Es existiert bereits eine aktive Einladung für diese E-Mail-Adresse.')); return; } // Erstelle Einladung $invitation = PartnerInvitation::create([ 'company_name' => $this->companyName, 'contact_first_name' => $this->contactFirstName ?: null, 'contact_last_name' => $this->contactLastName ?: null, 'role_id' => $this->roleId, 'email' => $this->email, 'token' => PartnerInvitation::generateToken(), 'status' => 'pending', 'expires_at' => now()->addWeeks($this->expiryWeeks), 'invited_by' => auth()->id(), ]); // Generiere Einladungs-URL $invitationUrl = route('partner.invitation.accept', ['token' => $invitation->token]); // Sende E-Mail try { Mail::to($this->email)->send(new PartnerInvitationMail($invitation, $invitationUrl)); $this->lastInvitation = $invitation; $this->showSuccessMessage = true; // Reset Form $this->reset(['companyName', 'contactFirstName', 'contactLastName', 'roleId', 'email', 'expiryWeeks']); // Setze default Rolle wieder $firstRole = $this->getPartnerRoles()->first(); $this->roleId = $firstRole?->id; $this->expiryWeeks = 1; session()->flash('message', __('Einladung erfolgreich versendet!')); } catch (\Exception $e) { $this->addError('email', __('Fehler beim Versenden der E-Mail: ') . $e->getMessage()); } } public function with(): array { return [ 'partnerRoles' => $this->getPartnerRoles(), 'recentInvitations' => PartnerInvitation::with(['invitedBy', 'role']) ->latest() ->take(10) ->get(), 'pendingCount' => PartnerInvitation::pending()->count(), 'acceptedCount' => PartnerInvitation::where('status', 'accepted')->count(), 'expiredCount' => PartnerInvitation::expired()->count(), ]; } }; ?>
{{-- Header --}}
{{ __('Partner einladen') }} {{ __('Laden Sie neue Partner zu Ihrer Plattform ein') }}
{{-- Statistics --}}
{{ __('Ausstehend') }} {{ $pendingCount }}
{{ __('Akzeptiert') }} {{ $acceptedCount }}
{{ __('Abgelaufen') }} {{ $expiredCount }}
{{-- Invitation Form --}}
{{ __('Neue Einladung senden') }} {{ __('Füllen Sie die Felder aus, um einen neuen Partner einzuladen') }}
{{ __('Firmenname') }} @error('companyName') {{ $message }} @enderror
{{ __('Vorname (optional)') }} @error('contactFirstName') {{ $message }} @enderror {{ __('Nachname (optional)') }} @error('contactLastName') {{ $message }} @enderror
{{ __('Partner-Typ') }} {{ __('Wählen Sie den Typ des Partners aus') }} @foreach($partnerRoles as $role) @if($role->icon) icon }} class="mr-2" /> @endif {{ $role->display_name ?? $role->name }} @endforeach @error('roleId') {{ $message }} @enderror {{ __('Gültigkeit der Einladung') }} {{ __('Wählen Sie zwischen 1 und 4 Wochen') }} @for($i = 1; $i <= 4; $i++) {{ $i }} {{ $i === 1 ? __('Woche') : __('Wochen') }} @endfor @error('expiryWeeks') {{ $message }} @enderror {{ __('E-Mail Adresse') }} {{ __('E-Mail des Ansprechpartners') }} @error('email') {{ $message }} @enderror {{-- Error Alert --}}
{{ __('Einladung senden') }} {{ __('Wird gesendet...') }}
{{-- Recent Invitations --}}
{{ __('Letzte Einladungen') }} {{ __('Übersicht der zuletzt versendeten Einladungen') }}
@forelse($recentInvitations as $invitation)
{{ $invitation->company_name }} @if($invitation->contact_full_name) • {{ $invitation->contact_full_name }} @endif
{{ $invitation->email }}
{{ ucfirst($invitation->status) }} {{ $invitation->role?->display_name ?? $invitation->role?->name }}
{{ __('Eingeladen am:') }} {{ $invitation->created_at->format('d.m.Y H:i') }} @if($invitation->status === 'pending')
{{ __('Gültig bis:') }} {{ $invitation->expires_at->format('d.m.Y H:i') }} @endif
@empty
{{ __('Noch keine Einladungen versendet') }}
@endforelse
{{-- Success Toast --}} @if (session()->has('message')) {{ session('message') }} @endif