presseportale/resources/views/livewire/customer/company-switcher.blade.php
Kevin Adametz 9b47296cea
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
Rebrand Hub+Flux
2026-05-20 15:44:15 +02:00

87 lines
2.9 KiB
PHP

<?php
use App\Services\Customer\CustomerCompanyContext;
use Livewire\Volt\Component;
new class extends Component
{
public string $activeCompany = 'all';
public function mount(CustomerCompanyContext $context): void
{
$companyId = $context->selectedCompanyId(auth()->user());
$this->activeCompany = $companyId === null ? 'all' : (string) $companyId;
}
public function updatedActiveCompany(CustomerCompanyContext $context): void
{
if ($this->activeCompany === 'all') {
$context->select(auth()->user(), null);
} elseif (is_numeric($this->activeCompany)) {
$context->select(auth()->user(), (int) $this->activeCompany);
}
$this->redirect($this->redirectTarget(), navigate: false);
}
public function with(CustomerCompanyContext $context): array
{
$user = auth()->user();
return [
'companies' => $context->companiesFor($user),
'selectedCompany' => $context->selectedCompany($user),
'context' => $context,
'user' => $user,
];
}
private function redirectTarget(): string
{
return (string) request()->headers->get('referer', route('me.dashboard'));
}
}; ?>
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-end">
@if ($companies->isNotEmpty())
<span class="badge hub dot hidden sm:inline-flex">{{ __('Aktive Firma') }}</span>
<div class="min-w-0 sm:w-72">
<flux:select wire:model.live="activeCompany" size="sm">
<option value="all">{{ __('Alle Firmen') }}</option>
@foreach ($companies as $company)
<option value="{{ $company->id }}">
{{ $company->name }} · {{ $context->roleLabelFor($company, $user) }}
</option>
@endforeach
</flux:select>
</div>
<div class="hidden max-w-48 truncate text-[11px] uppercase tracking-[0.6px] font-semibold text-[color:var(--color-ink-3)] lg:block">
@if ($selectedCompany)
{{ $selectedCompany->portal?->label() ?? __('Portal unbekannt') }}
@else
{{ __('Aggregierte Sicht') }}
@endif
</div>
@if ($selectedCompany)
<flux:button
size="sm"
variant="ghost"
icon="building-office"
href="{{ route('me.press-kits.show', $selectedCompany->id) }}"
wire:navigate
>
{{ __('Firma öffnen') }}
</flux:button>
@else
<flux:button size="sm" variant="ghost" icon="building-office" href="{{ route('me.press-kits.index') }}" wire:navigate>
{{ __('Firmen') }}
</flux:button>
@endif
@else
<span class="badge warn dot">{{ __('Keine Firma zugeordnet') }}</span>
@endif
</div>