Phase 8 (Rest) + Umbauten vom 10./11.06.: - Ein Titelbild pro PM (Cover 1280x580), SVG-Platzhalter-Set + Picker, PressReleaseCoverImage-Resolver - Lizenz-/Rechteformular nach "Lizenztyp Bildupload" (7 Lizenztypen, Personen-/Sachrechte-Status, bedingte Pflichtfelder, Risikohinweise) - Veroeffentlichungs-Box vereinfacht (Embargo aus der Form-UI entfernt), geplante Termine in Europe/Berlin (Speicherung UTC, DISPLAY_TIMEZONE) - Quota-Stub (users.press_release_quota) + monatlicher Reset-Command - Einreichungs-Modal einheitlich in Show/Create/Edit; Ghost-Buttons auf filled; PM-Editor-Layout responsive entkoppelt (.pr-editor-layout) KI-Pruef-Pipeline (Phasen 1-5 des Entwicklungsplans): - API-Haertung: status nicht mehr per API setzbar, eigene Submit-Route durch denselben Funnel (Blacklist, Quota, Status-Log) - Klassifikation Rot/Gelb/Gruen asynchron (Queue classification, OpenAI-Treiber + deterministischer Fallback), ki_audits-Audit-Log - Routing: Rot -> rejected + Mail, Gelb -> Review-Queue, Gruen -> Auto-Publish; Scheduler publiziert nur gruene faellige PMs - Content-Score 0-100 -> Stufe (Standard/Geprueft/Hochwertig) inkl. Editor-Panel und Badges; Re-Klassifikation/-Score bei Aenderung - Admin: KI-Badge + Filter, On-Demand-Pruefung mit Anbieter-Override Suite: 442 passed, 4 skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
476 lines
22 KiB
PHP
476 lines
22 KiB
PHP
<?php
|
|
|
|
use App\Enums\Portal;
|
|
use App\Models\Company;
|
|
use App\Models\Contact;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('components.layouts.app'), Title('Firma anzeigen')] class extends Component
|
|
{
|
|
public int $id;
|
|
|
|
public string $activeTab = 'overview';
|
|
|
|
public string $contactSearch = '';
|
|
|
|
public string $contactLookup = '';
|
|
|
|
public ?int $selectedExistingContactId = null;
|
|
|
|
public function updatedSelectedExistingContactId(): void
|
|
{
|
|
if ($this->selectedExistingContactId) {
|
|
$this->attachExistingContact();
|
|
}
|
|
}
|
|
|
|
public function mount(int $id): void
|
|
{
|
|
$this->id = $id;
|
|
|
|
$companyExists = Company::query()->whereKey($id)->exists();
|
|
|
|
if (! $companyExists) {
|
|
session()->flash('error', __('Die angeforderte Firma wurde nicht gefunden.'));
|
|
$this->redirect(route('admin.companies.index'), navigate: true);
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function setTab(string $tab): void
|
|
{
|
|
if (in_array($tab, ['overview', 'contacts'], true)) {
|
|
$this->activeTab = $tab;
|
|
}
|
|
}
|
|
|
|
public function updatedContactLookup(): void
|
|
{
|
|
$this->selectedExistingContactId = null;
|
|
}
|
|
|
|
public function attachExistingContact(): void
|
|
{
|
|
if (! $this->selectedExistingContactId) {
|
|
return;
|
|
}
|
|
|
|
$company = Company::query()->find($this->id);
|
|
if (! $company) {
|
|
session()->flash('error', __('Die angeforderte Firma wurde nicht gefunden.'));
|
|
|
|
return;
|
|
}
|
|
|
|
$contact = Contact::query()->find($this->selectedExistingContactId);
|
|
if (! $contact) {
|
|
session()->flash('error', __('Der ausgewählte Kontakt wurde nicht gefunden.'));
|
|
|
|
return;
|
|
}
|
|
|
|
if ($contact->company_id === $company->id) {
|
|
session()->flash('info', __('Der Kontakt ist bereits dieser Firma zugeordnet.'));
|
|
|
|
return;
|
|
}
|
|
|
|
$contact->update(['company_id' => $company->id]);
|
|
|
|
$this->contactLookup = '';
|
|
$this->selectedExistingContactId = null;
|
|
session()->flash('success', __('Kontakt wurde der Firma zugeordnet.'));
|
|
}
|
|
|
|
public function with(): array
|
|
{
|
|
$company = Company::query()
|
|
->with([
|
|
'pressReleases' => fn ($query) => $query->latest('id')->limit(10),
|
|
'users:id,name,email',
|
|
])
|
|
->withCount(['pressReleases', 'contacts', 'users'])
|
|
->find($this->id);
|
|
|
|
if (! $company) {
|
|
return [
|
|
'company' => Company::make([
|
|
'id' => $this->id,
|
|
'name' => __('Unbekannte Firma'),
|
|
'is_active' => false,
|
|
]),
|
|
'filteredContacts' => collect(),
|
|
'filteredContactsTotal' => 0,
|
|
'contactLookupResults' => collect(),
|
|
'recentPressReleases' => collect(),
|
|
];
|
|
}
|
|
|
|
$filteredContacts = collect();
|
|
$filteredContactsTotal = 0;
|
|
|
|
if ($this->activeTab === 'contacts') {
|
|
$contactsQuery = Contact::query()
|
|
->where('company_id', $company->id)
|
|
->when(filled($this->contactSearch), function ($query): void {
|
|
$search = trim($this->contactSearch);
|
|
|
|
if ($this->supportsFullTextSearch($search)) {
|
|
$query->whereFullText(['first_name', 'last_name', 'email', 'responsibility'], $search);
|
|
|
|
return;
|
|
}
|
|
|
|
$query->where(function ($query) use ($search): void {
|
|
$query->where('first_name', 'like', '%'.$search.'%')
|
|
->orWhere('last_name', 'like', '%'.$search.'%')
|
|
->orWhere('email', 'like', '%'.$search.'%')
|
|
->orWhere('responsibility', 'like', '%'.$search.'%');
|
|
});
|
|
});
|
|
|
|
$filteredContactsTotal = (clone $contactsQuery)->count();
|
|
$filteredContacts = $contactsQuery
|
|
->orderBy('last_name')
|
|
->orderBy('first_name')
|
|
->limit(100)
|
|
->get(['id', 'company_id', 'portal', 'first_name', 'last_name', 'responsibility', 'email']);
|
|
}
|
|
|
|
$contactLookupResults = collect();
|
|
$lookupTerm = trim($this->contactLookup);
|
|
|
|
if ($this->activeTab === 'contacts' && mb_strlen($lookupTerm) >= 1) {
|
|
$contactLookupResults = Contact::withoutGlobalScopes()
|
|
->with('company:id,name')
|
|
->where('company_id', '!=', $company->id)
|
|
->where(function ($query) use ($lookupTerm): void {
|
|
if ($this->supportsFullTextSearch($lookupTerm)) {
|
|
$query->whereFullText(['first_name', 'last_name', 'email', 'responsibility'], $lookupTerm);
|
|
|
|
return;
|
|
}
|
|
|
|
$query
|
|
->where('first_name', 'like', '%'.$lookupTerm.'%')
|
|
->orWhere('last_name', 'like', '%'.$lookupTerm.'%')
|
|
->orWhere('email', 'like', '%'.$lookupTerm.'%');
|
|
})
|
|
->orderBy('last_name')
|
|
->orderBy('first_name')
|
|
->limit(50)
|
|
->get(['id', 'company_id', 'first_name', 'last_name', 'email']);
|
|
}
|
|
|
|
return [
|
|
'company' => $company,
|
|
'filteredContacts' => $filteredContacts,
|
|
'filteredContactsTotal' => $filteredContactsTotal,
|
|
'contactLookupResults' => $contactLookupResults,
|
|
'recentPressReleases' => $company->pressReleases,
|
|
];
|
|
}
|
|
|
|
private function supportsFullTextSearch(string $term): bool
|
|
{
|
|
return mb_strlen($term) >= 3
|
|
&& in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'], true);
|
|
}
|
|
|
|
private function portalBadgeColor(?Portal $portal): string
|
|
{
|
|
return match ($portal) {
|
|
Portal::Presseecho => 'blue',
|
|
Portal::Businessportal24 => 'purple',
|
|
Portal::Both => 'zinc',
|
|
default => 'zinc',
|
|
};
|
|
}
|
|
}; ?>
|
|
|
|
<div class="space-y-8">
|
|
@if (session('success'))
|
|
<div class="px-4 py-3 rounded-[5px] border text-[12.5px]
|
|
bg-[color:var(--color-ok-soft)] border-[color:var(--color-ok)]/30 text-[color:var(--color-gain-deep)]">
|
|
{{ session('success') }}
|
|
</div>
|
|
@endif
|
|
@if (session('error'))
|
|
<div class="px-4 py-3 rounded-[5px] border text-[12.5px]
|
|
bg-[color:var(--color-err-soft)] border-[color:var(--color-err)]/30 text-[color:var(--color-loss)]">
|
|
{{ session('error') }}
|
|
</div>
|
|
@endif
|
|
@if (session('info'))
|
|
<div class="px-4 py-3 rounded-[5px] border text-[12.5px]
|
|
bg-[color:var(--color-hub-soft)] border-[color:var(--color-hub-soft-2)] text-[color:var(--color-ink-2)]">
|
|
{{ session('info') }}
|
|
</div>
|
|
@endif
|
|
|
|
{{-- ============== PAGE HEADER ============== --}}
|
|
@php($logoUrl = $company->logoUrl())
|
|
<header class="grid items-end gap-8" style="grid-template-columns:1fr auto;">
|
|
<div class="min-w-0">
|
|
<div class="flex items-center gap-3 mb-3 flex-wrap">
|
|
<span class="badge hub dot">{{ __('Admin Backend') }}</span>
|
|
<span class="eyebrow muted">{{ __('Stammdaten · Firma') }}</span>
|
|
@if ($company->is_active)
|
|
<span class="badge ok">{{ __('Aktiv') }}</span>
|
|
@else
|
|
<span class="badge err">{{ __('Inaktiv') }}</span>
|
|
@endif
|
|
<span class="badge hub">{{ $company->portal?->label() ?? __('Unbekannt') }}</span>
|
|
<span class="badge hub">ID {{ $company->id }}</span>
|
|
</div>
|
|
<div class="flex items-start gap-4">
|
|
@if ($logoUrl)
|
|
<img src="{{ $logoUrl }}" width="64" height="64"
|
|
class="h-16 max-h-16 w-16 max-w-16 rounded-[6px] border border-[color:var(--color-bg-rule)] object-contain bg-[color:var(--color-bg-elev)] flex-shrink-0"
|
|
alt="{{ $company->name }}">
|
|
@else
|
|
<div class="flex h-16 w-16 items-center justify-center rounded-[6px]
|
|
border border-[color:var(--color-bg-rule)] bg-[color:var(--color-bg-elev)] flex-shrink-0">
|
|
<flux:icon.building-office class="size-7 text-[color:var(--color-ink-3)]" />
|
|
</div>
|
|
@endif
|
|
<div class="min-w-0">
|
|
<h1 class="text-[30px] font-bold tracking-[-0.6px] leading-[1.15] m-0 text-[color:var(--color-ink)] break-words">
|
|
{{ $company->name }}
|
|
</h1>
|
|
@if ($company->website)
|
|
<a href="{{ $company->website }}" target="_blank" rel="noopener"
|
|
class="text-[12.5px] text-[color:var(--color-hub)] underline underline-offset-2 decoration-[color:var(--color-hub)]/40 hover:decoration-[color:var(--color-hub)] mt-1 inline-block">
|
|
{{ $company->website }}
|
|
</a>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2 flex-shrink-0">
|
|
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.companies.index') }}" wire:navigate>
|
|
{{ __('Zurück') }}
|
|
</flux:button>
|
|
@if (\Illuminate\Support\Facades\Route::has('admin.companies.contacts.create'))
|
|
<flux:button variant="filled" icon="user-plus" href="{{ route('admin.companies.contacts.create', ['companyId' => $company->id]) }}" wire:navigate>
|
|
{{ __('Kontakt hinzufügen') }}
|
|
</flux:button>
|
|
@endif
|
|
<flux:button variant="primary" icon="pencil" href="{{ route('admin.companies.edit', $company->id) }}" wire:navigate>
|
|
{{ __('Bearbeiten') }}
|
|
</flux:button>
|
|
</div>
|
|
</header>
|
|
|
|
{{-- ============== KPI-Reihe ============== --}}
|
|
<section class="grid grid-cols-1 gap-4 sm:grid-cols-3">
|
|
<x-portal.stat-card variant="primary" :label="__('Pressemitteilungen')" :value="number_format($company->press_releases_count)">
|
|
<x-slot:meta>{{ __('insgesamt') }}</x-slot:meta>
|
|
<x-slot:trend>{{ __('Content-Output dieser Firma') }}</x-slot:trend>
|
|
</x-portal.stat-card>
|
|
<x-portal.stat-card variant="ok" :label="__('Kontakte')" :value="number_format($company->contacts_count)">
|
|
<x-slot:meta>{{ __('Ansprechpartner') }}</x-slot:meta>
|
|
<x-slot:trend>{{ __('für PMs verfügbar') }}</x-slot:trend>
|
|
</x-portal.stat-card>
|
|
<x-portal.stat-card variant="muted" :label="__('Verknüpfte Benutzer')" :value="number_format($company->users_count)">
|
|
<x-slot:meta>{{ __('Owner & Co-Editors') }}</x-slot:meta>
|
|
<x-slot:trend>{{ __('Backend-Zugriff') }}</x-slot:trend>
|
|
</x-portal.stat-card>
|
|
</section>
|
|
|
|
{{-- ============== TABS ============== --}}
|
|
<nav class="flex items-center gap-2 border-b border-[color:var(--color-bg-rule)]">
|
|
<button type="button" wire:click="setTab('overview')"
|
|
@class([
|
|
'px-4 py-2.5 text-[12.5px] font-semibold border-b-2 transition-colors',
|
|
'border-[color:var(--color-hub)] text-[color:var(--color-ink)]' => $activeTab === 'overview',
|
|
'border-transparent text-[color:var(--color-ink-3)] hover:text-[color:var(--color-ink)]' => $activeTab !== 'overview',
|
|
])>
|
|
{{ __('Überblick') }}
|
|
</button>
|
|
<button type="button" wire:click="setTab('contacts')"
|
|
@class([
|
|
'px-4 py-2.5 text-[12.5px] font-semibold border-b-2 transition-colors',
|
|
'border-[color:var(--color-hub)] text-[color:var(--color-ink)]' => $activeTab === 'contacts',
|
|
'border-transparent text-[color:var(--color-ink-3)] hover:text-[color:var(--color-ink)]' => $activeTab !== 'contacts',
|
|
])>
|
|
{{ __('Kontakte') }}
|
|
</button>
|
|
</nav>
|
|
|
|
@if ($activeTab === 'overview')
|
|
<div class="grid gap-6 lg:grid-cols-2">
|
|
<article class="panel">
|
|
<div class="panel-head">
|
|
<span class="section-eyebrow">{{ __('Kontaktinformationen') }}</span>
|
|
</div>
|
|
<dl class="p-5 space-y-2.5 text-[12.5px]">
|
|
<div class="flex justify-between gap-2">
|
|
<dt class="text-[color:var(--color-ink-3)]">{{ __('E-Mail') }}</dt>
|
|
<dd class="text-[color:var(--color-ink)] text-right break-all">{{ $company->email ?: __('Keine E-Mail hinterlegt') }}</dd>
|
|
</div>
|
|
<div class="flex justify-between gap-2">
|
|
<dt class="text-[color:var(--color-ink-3)]">{{ __('Telefon') }}</dt>
|
|
<dd class="text-[color:var(--color-ink)]">{{ $company->phone ?: __('Kein Telefon hinterlegt') }}</dd>
|
|
</div>
|
|
<div class="flex justify-between gap-2">
|
|
<dt class="text-[color:var(--color-ink-3)]">{{ __('Website') }}</dt>
|
|
<dd class="text-[color:var(--color-ink)] text-right break-all">{{ $company->website ?: __('Keine Website hinterlegt') }}</dd>
|
|
</div>
|
|
</dl>
|
|
</article>
|
|
|
|
<article class="panel">
|
|
<div class="panel-head">
|
|
<span class="section-eyebrow">{{ __('Adresse') }}</span>
|
|
</div>
|
|
<dl class="p-5 space-y-2.5 text-[12.5px]">
|
|
<div class="flex justify-between gap-2">
|
|
<dt class="text-[color:var(--color-ink-3)]">{{ __('Anschrift') }}</dt>
|
|
<dd class="text-[color:var(--color-ink)] text-right whitespace-pre-line">{{ $company->address ?: __('Keine Adresse hinterlegt') }}</dd>
|
|
</div>
|
|
<div class="flex justify-between gap-2">
|
|
<dt class="text-[color:var(--color-ink-3)]">{{ __('Land') }}</dt>
|
|
<dd class="text-[color:var(--color-ink)]">{{ $company->country_code ?: __('Kein Land hinterlegt') }}</dd>
|
|
</div>
|
|
</dl>
|
|
</article>
|
|
|
|
<article class="panel lg:col-span-2">
|
|
<div class="panel-head">
|
|
<span class="section-eyebrow">{{ __('Aktuelle Pressemitteilungen') }}</span>
|
|
<flux:button size="sm" variant="filled" href="{{ route('admin.press-releases.index', ['company' => $company->id]) }}" wire:navigate>
|
|
{{ __('Alle anzeigen') }}
|
|
</flux:button>
|
|
</div>
|
|
<div class="divide-y divide-[color:var(--color-bg-rule)]">
|
|
@forelse ($recentPressReleases as $pressRelease)
|
|
<a href="{{ route('admin.press-releases.show', $pressRelease->id) }}" wire:navigate
|
|
class="flex items-center justify-between gap-3 px-5 py-3 hover:bg-[color:var(--color-bg-elev)] transition-colors">
|
|
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] truncate">
|
|
{{ $pressRelease->title ?? __('Ohne Titel') }}
|
|
</span>
|
|
<span class="text-[11.5px] text-[color:var(--color-ink-3)] flex-shrink-0">
|
|
{{ $pressRelease->created_at?->format('d.m.Y') ?? '-' }}
|
|
</span>
|
|
</a>
|
|
@empty
|
|
<div class="px-5 py-6 text-[12.5px] text-[color:var(--color-ink-3)]">
|
|
{{ __('Keine Pressemitteilungen vorhanden') }}
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
</article>
|
|
</div>
|
|
@endif
|
|
|
|
@if ($activeTab === 'contacts')
|
|
<article class="panel">
|
|
<div class="panel-head">
|
|
<span class="section-eyebrow">{{ __('Ansprechpartner') }}</span>
|
|
<span class="text-[11.5px] text-[color:var(--color-ink-3)]">
|
|
{{ $filteredContactsTotal }} {{ __('Einträge') }}
|
|
</span>
|
|
</div>
|
|
<div class="p-5 space-y-4">
|
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
|
|
<flux:input
|
|
wire:model.live.debounce.300ms="contactSearch"
|
|
placeholder="{{ __('Kontakte durchsuchen...') }}"
|
|
icon="magnifying-glass"
|
|
class="flex-1"
|
|
/>
|
|
@if (\Illuminate\Support\Facades\Route::has('admin.companies.contacts.create'))
|
|
<flux:button size="sm" icon="plus" href="{{ route('admin.companies.contacts.create', ['companyId' => $company->id]) }}" wire:navigate>
|
|
{{ __('Neu') }}
|
|
</flux:button>
|
|
@endif
|
|
</div>
|
|
|
|
<div class="rounded-[5px] border border-[color:var(--color-bg-rule)] bg-[color:var(--color-bg-elev)] p-4">
|
|
<div class="text-[11px] uppercase tracking-[0.6px] text-[color:var(--color-ink-3)] font-semibold mb-2">
|
|
{{ __('Bestehenden Kontakt zuordnen') }}
|
|
</div>
|
|
<flux:select
|
|
wire:model.live="selectedExistingContactId"
|
|
variant="combobox"
|
|
:filter="false"
|
|
placeholder="{{ __('Kontakt suchen und auswählen…') }}"
|
|
>
|
|
<x-slot name="input">
|
|
<flux:select.input
|
|
wire:model.live.debounce.300ms="contactLookup"
|
|
placeholder="{{ __('Name oder E-Mail…') }}"
|
|
/>
|
|
</x-slot>
|
|
@foreach ($contactLookupResults as $lookupContact)
|
|
@php($lookupName = trim(($lookupContact->first_name ?? '').' '.($lookupContact->last_name ?? '')) ?: __('Kontakt ohne Name'))
|
|
<flux:select.option :value="$lookupContact->id" wire:key="lc-{{ $lookupContact->id }}">
|
|
{{ $lookupName }}
|
|
<span class="text-[color:var(--color-ink-3)]">
|
|
@if ($lookupContact->email)
|
|
· {{ $lookupContact->email }}
|
|
@endif
|
|
· {{ $lookupContact->company?->name ?? __('Unbekannte Firma') }}
|
|
</span>
|
|
</flux:select.option>
|
|
@endforeach
|
|
<x-slot name="empty">
|
|
<flux:select.option.empty>
|
|
@if (blank(trim($contactLookup)))
|
|
{{ __('Mindestens 1 Zeichen eingeben…') }}
|
|
@else
|
|
{{ __('Kein Kontakt gefunden.') }}
|
|
@endif
|
|
</flux:select.option.empty>
|
|
</x-slot>
|
|
</flux:select>
|
|
</div>
|
|
|
|
<div class="space-y-2">
|
|
@forelse ($filteredContacts as $contact)
|
|
<div class="rounded-[5px] border border-[color:var(--color-bg-rule)] bg-[color:var(--color-bg-elev)] p-3">
|
|
<div class="flex items-start justify-between gap-3">
|
|
<div class="min-w-0">
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
<span class="text-[13px] font-semibold text-[color:var(--color-ink)]">
|
|
{{ trim(($contact->first_name ?? '').' '.($contact->last_name ?? '')) ?: __('Kontakt ohne Name') }}
|
|
</span>
|
|
<span class="badge hub">{{ $contact->portal?->label() ?? __('Unbekannt') }}</span>
|
|
</div>
|
|
<div class="text-[12px] text-[color:var(--color-ink-3)] mt-0.5">
|
|
{{ $contact->responsibility ?: __('Keine Rolle hinterlegt') }}
|
|
</div>
|
|
@if ($contact->email)
|
|
<a href="mailto:{{ $contact->email }}"
|
|
class="text-[12px] text-[color:var(--color-hub)] underline underline-offset-2 decoration-[color:var(--color-hub)]/40 hover:decoration-[color:var(--color-hub)] mt-0.5 inline-block">
|
|
{{ $contact->email }}
|
|
</a>
|
|
@endif
|
|
</div>
|
|
@if (\Illuminate\Support\Facades\Route::has('admin.contacts.edit'))
|
|
<flux:button size="sm" variant="filled" icon="pencil" href="{{ route('admin.contacts.edit', $contact->id) }}" wire:navigate />
|
|
@endif
|
|
</div>
|
|
</div>
|
|
@empty
|
|
<div class="rounded-[5px] border border-dashed border-[color:var(--color-bg-rule)] p-4 text-[12.5px] text-[color:var(--color-ink-3)]">
|
|
{{ __('Keine Kontakte gefunden') }}
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
|
|
@if ($filteredContactsTotal > $filteredContacts->count())
|
|
<p class="text-[11.5px] text-[color:var(--color-ink-3)] m-0">
|
|
{{ __('Es werden die ersten :count Kontakte angezeigt. Bitte Suche eingrenzen, um weitere Treffer zu finden.', ['count' => $filteredContacts->count()]) }}
|
|
</p>
|
|
@endif
|
|
</div>
|
|
</article>
|
|
@endif
|
|
</div>
|