91 lines
3.1 KiB
PHP
91 lines
3.1 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())
|
|
<div class="hidden text-xs font-medium uppercase tracking-wider text-zinc-500 dark:text-zinc-400 sm:block">
|
|
{{ __('Aktive Firma') }}
|
|
</div>
|
|
|
|
<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-xs text-zinc-500 dark:text-zinc-400 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
|
|
<div class="rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200">
|
|
{{ __('Keine Firma zugeordnet') }}
|
|
</div>
|
|
@endif
|
|
</div>
|