96 lines
3.4 KiB
PHP
96 lines
3.4 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();
|
|
$selectedCompanyId = $context->selectedCompanyId($user);
|
|
$companies = $context->switcherCompaniesFor($user, $selectedCompanyId, 51);
|
|
$visibleCompanies = $companies->take(50)->values();
|
|
|
|
return [
|
|
'companies' => $visibleCompanies,
|
|
'hasMoreCompanies' => $companies->count() > 50,
|
|
'selectedCompany' => $selectedCompanyId === null
|
|
? null
|
|
: $visibleCompanies->firstWhere('id', $selectedCompanyId),
|
|
'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
|
|
@if ($hasMoreCompanies)
|
|
<option value="all" disabled>{{ __('Weitere Firmen über „Firmen" öffnen') }}</option>
|
|
@endif
|
|
</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>
|