presseportale/resources/views/livewire/admin/users/show.blade.php
Kevin Adametz 5b8bdf4182
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
12-05-2026 Frontend dev
2026-05-12 18:32:33 +02:00

239 lines
12 KiB
PHP

<?php
use App\Models\User;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Title;
use Livewire\Volt\Component;
new #[Layout('components.layouts.app'), Title('Benutzer anzeigen')] class extends Component
{
#[Locked]
public int $id;
public function mount(int $id): void
{
$this->id = $id;
if (! User::query()->whereKey($id)->exists()) {
session()->flash('error', __('Der angeforderte Benutzer wurde nicht gefunden.'));
$this->redirect(route('admin.users.index'), navigate: true);
return;
}
}
public function companyUserRoleLabel(?string $role): string
{
return match ($role ?? 'member') {
'owner' => __('Inhaber'),
'responsible' => __('Verantwortlich'),
'member' => __('Mitglied'),
default => (string) ($role ?? 'member'),
};
}
public function with(): array
{
$user = User::query()
->with([
'roles' => fn ($query) => $query->orderBy('name'),
'companies' => fn ($query) => $query
->select(['companies.id', 'companies.name', 'companies.slug', 'companies.email', 'companies.phone', 'companies.portal', 'companies.is_active'])
->withCount('contacts')
->orderBy('name'),
'companies.contacts' => fn ($query) => $query
->select(['contacts.id', 'contacts.company_id', 'contacts.portal', 'contacts.first_name', 'contacts.last_name', 'contacts.responsibility', 'contacts.email', 'contacts.phone'])
->orderBy('last_name')
->orderBy('first_name')
->limit(10),
'billingAddress',
])
->find($this->id);
return [
'user' => $user,
];
}
}; ?>
<div class="space-y-6">
@if (!$user)
<flux:card>
<flux:heading size="lg">{{ __('Benutzer nicht gefunden') }}</flux:heading>
<flux:button class="mt-4" href="{{ route('admin.users.index') }}" wire:navigate>
{{ __('Zurück zur Übersicht') }}
</flux:button>
</flux:card>
@else
<flux:card>
<div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
<div>
<flux:heading size="xl">{{ $user->name }}</flux:heading>
<flux:text class="text-sm text-zinc-500">{{ $user->email }}</flux:text>
<flux:text class="text-xs text-zinc-500">ID: {{ $user->id }}</flux:text>
</div>
<div class="flex gap-2">
<flux:button variant="ghost" href="{{ route('admin.users.index') }}" wire:navigate>
{{ __('Zurück') }}
</flux:button>
<flux:button icon="pencil" href="{{ route('admin.users.edit', $user->id) }}" wire:navigate>
{{ __('Bearbeiten') }}
</flux:button>
</div>
</div>
</flux:card>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-4">
<flux:card>
<flux:text class="text-xs text-zinc-500">{{ __('Portal') }}</flux:text>
<flux:text weight="semibold">{{ $user->portal?->label() ?? '-' }}</flux:text>
</flux:card>
<flux:card>
<flux:text class="text-xs text-zinc-500">{{ __('Typ') }}</flux:text>
<flux:text weight="semibold">{{ $user->registration_type?->label() ?? '-' }}</flux:text>
</flux:card>
<flux:card>
<flux:text class="text-xs text-zinc-500">{{ __('Status') }}</flux:text>
@if ($user->is_active)
<flux:badge color="green" size="sm">{{ __('Aktiv') }}</flux:badge>
@else
<flux:badge color="red" size="sm">{{ __('Inaktiv') }}</flux:badge>
@endif
</flux:card>
<flux:card>
<flux:text class="text-xs text-zinc-500">{{ __('Letzter Login') }}</flux:text>
<flux:text weight="semibold">{{ $user->last_login_at?->format('d.m.Y H:i') ?? __('Nie') }}</flux:text>
@if ($user->last_login_ip)
<flux:text class="text-xs text-zinc-500">{{ $user->last_login_ip }}</flux:text>
@endif
</flux:card>
</div>
<flux:card>
<flux:heading size="lg" class="mb-4">{{ __('Rollen') }}</flux:heading>
<div class="flex flex-wrap gap-2">
@forelse($user->roles as $role)
<flux:badge color="zinc" size="sm">{{ $role->name }}</flux:badge>
@empty
<flux:text class="text-sm text-zinc-500">{{ __('Keine Rollen hinterlegt') }}</flux:text>
@endforelse
</div>
</flux:card>
<flux:card>
<flux:heading size="lg" class="mb-4">{{ __('Rechnungsadresse') }}</flux:heading>
@if ($user->billingAddress)
<div class="space-y-1">
<flux:text>{{ $user->billingAddress->name }}</flux:text>
<flux:text>{{ $user->billingAddress->address1 }}</flux:text>
@if ($user->billingAddress->address2)
<flux:text>{{ $user->billingAddress->address2 }}</flux:text>
@endif
<flux:text>{{ $user->billingAddress->postal_code }} {{ $user->billingAddress->city }}</flux:text>
<flux:text>{{ $user->billingAddress->country_code }}</flux:text>
</div>
@else
<flux:text class="text-sm text-zinc-500">{{ __('Keine Rechnungsadresse hinterlegt') }}</flux:text>
@endif
</flux:card>
<flux:card>
<flux:heading size="lg" class="mb-4">{{ __('Verknüpfte Firmen und Kontakte') }}</flux:heading>
<flux:subheading class="mb-4">
{{ __('Kontakte sind die Ansprechpartner der verknüpften Firmen (wie in der Bearbeiten-Ansicht).') }}
</flux:subheading>
<div class="space-y-4">
@forelse($user->companies as $company)
<div class="rounded-lg border border-zinc-200 p-4 dark:border-zinc-700">
<div class="mb-3 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
<div class="min-w-0 flex-1">
@if (\Illuminate\Support\Facades\Route::has('admin.companies.show'))
<a href="{{ route('admin.companies.show', $company->id) }}" wire:navigate
class="block">
<flux:text weight="semibold"
class="text-blue-600 hover:underline dark:text-blue-400">
{{ $company->name }}
</flux:text>
</a>
@else
<flux:text weight="semibold">{{ $company->name }}</flux:text>
@endif
<flux:text class="text-xs text-zinc-500">{{ $company->slug }}</flux:text>
<div class="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-zinc-500">
@if ($company->email)
<span>{{ $company->email }}</span>
@endif
@if ($company->phone)
<span>{{ $company->phone }}</span>
@endif
</div>
</div>
<div class="flex flex-wrap items-center gap-2">
<flux:badge color="zinc" size="sm">
{{ $this->companyUserRoleLabel($company->pivot?->role ?? 'member') }}
</flux:badge>
<flux:badge color="zinc" size="sm">
{{ $company->portal?->label() ?? '—' }}
</flux:badge>
@if (!$company->is_active)
<flux:badge color="red" size="sm">{{ __('Inaktiv') }}</flux:badge>
@endif
</div>
</div>
@if ($company->contacts->isNotEmpty())
<div class="space-y-2">
@foreach ($company->contacts as $contact)
<div
class="flex flex-col gap-2 rounded-md bg-zinc-50 p-2 dark:bg-zinc-900 sm:flex-row sm:items-center sm:justify-between">
<div class="min-w-0">
<flux:text class="text-sm" weight="medium">
{{ trim(($contact->first_name ?? '') . ' ' . ($contact->last_name ?? '')) ?: __('Kontakt ohne Name') }}
</flux:text>
<flux:text class="text-xs text-zinc-500">
{{ $contact->responsibility ?? __('Keine Rolle hinterlegt') }}
</flux:text>
<div class="mt-0.5 flex flex-wrap items-center gap-2 text-xs text-zinc-500">
@if ($contact->email)
<a href="mailto:{{ $contact->email }}"
class="text-blue-600 hover:underline dark:text-blue-400">{{ $contact->email }}</a>
@endif
@if ($contact->phone)
<span>{{ $contact->phone }}</span>
@endif
</div>
</div>
<div class="flex shrink-0 items-center gap-2">
<flux:badge color="zinc" size="sm">
{{ $contact->portal?->label() ?? '—' }}</flux:badge>
@if (\Illuminate\Support\Facades\Route::has('admin.contacts.edit'))
<flux:button size="sm" variant="ghost" icon="pencil"
href="{{ route('admin.contacts.edit', $contact->id) }}"
wire:navigate>
{{ __('Bearbeiten') }}
</flux:button>
@endif
</div>
</div>
@endforeach
@if ($company->contacts_count > $company->contacts->count())
<flux:text class="text-xs text-zinc-500">
{{ __(':count weitere Kontakte werden hier nicht geladen. Öffne die Firma, um alle Kontakte zu sehen.', ['count' => $company->contacts_count - $company->contacts->count()]) }}
</flux:text>
@endif
</div>
@else
<flux:text class="text-xs text-zinc-500">{{ __('Keine Kontakte bei dieser Firma') }}
</flux:text>
@endif
</div>
@empty
<flux:text class="text-sm text-zinc-500">{{ __('Keine Firmen verknüpft') }}</flux:text>
@endforelse
</div>
</flux:card>
@endif
</div>