218 lines
8.4 KiB
PHP
218 lines
8.4 KiB
PHP
<?php
|
|
|
|
use App\Enums\CompanyType;
|
|
use App\Enums\Portal;
|
|
use App\Models\Company;
|
|
use Flux\Flux;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('components.layouts.app'), Title('Neue Firma anlegen')] class extends Component
|
|
{
|
|
public string $name = '';
|
|
|
|
public string $portal = '';
|
|
|
|
public string $type = '';
|
|
|
|
public string $address = '';
|
|
|
|
public string $email = '';
|
|
|
|
public string $phone = '';
|
|
|
|
public string $website = '';
|
|
|
|
public string $countryCode = 'DE';
|
|
|
|
public bool $disableFooterCode = false;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->type = CompanyType::Company->value;
|
|
$this->countryCode = (string) config('countries.default', 'DE');
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
try {
|
|
$validated = $this->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'portal' => ['required', Rule::in([
|
|
Portal::Presseecho->value,
|
|
Portal::Businessportal24->value,
|
|
Portal::Both->value,
|
|
])],
|
|
'type' => ['required', Rule::in([CompanyType::Company->value, CompanyType::Agency->value])],
|
|
'address' => ['nullable', 'string', 'max:1000'],
|
|
'email' => ['nullable', 'email', 'max:190'],
|
|
'phone' => ['nullable', 'string', 'max:40'],
|
|
'website' => ['nullable', 'url', 'max:190'],
|
|
'countryCode' => ['nullable', 'string', 'size:2', Rule::in(array_keys((array) config('countries.items', [])))],
|
|
]);
|
|
} catch (ValidationException $e) {
|
|
$count = array_sum(array_map('count', $e->errors()));
|
|
Flux::toast(
|
|
heading: __('Bitte Eingaben prüfen'),
|
|
text: $count > 1
|
|
? __(':count Felder benötigen deine Aufmerksamkeit.', ['count' => $count])
|
|
: __('Ein Feld benötigt deine Aufmerksamkeit.'),
|
|
variant: 'danger',
|
|
duration: 6000,
|
|
);
|
|
|
|
throw $e;
|
|
}
|
|
|
|
$user = auth()->user();
|
|
|
|
$company = new Company([
|
|
'portal' => $validated['portal'],
|
|
'owner_user_id' => $user->id,
|
|
'type' => $validated['type'],
|
|
'name' => $validated['name'],
|
|
'address' => $validated['address'] ?: null,
|
|
'country_code' => $validated['countryCode'] ?: null,
|
|
'email' => $validated['email'] ?: null,
|
|
'phone' => $validated['phone'] ?: null,
|
|
'website' => $validated['website'] ?: null,
|
|
'is_active' => true,
|
|
'disable_footer_code' => $this->disableFooterCode,
|
|
]);
|
|
|
|
$company->slug = $company->generateUniqueSlug($validated['name'], [
|
|
'portal' => $validated['portal'],
|
|
]);
|
|
|
|
$company->save();
|
|
|
|
$user->companies()->syncWithoutDetaching([
|
|
$company->id => ['role' => 'owner'],
|
|
]);
|
|
|
|
Flux::toast(
|
|
heading: __('Firma angelegt'),
|
|
text: __('„:name" wurde angelegt und steht sofort zur Verfügung.', ['name' => $company->name]),
|
|
variant: 'success',
|
|
);
|
|
|
|
$this->redirect(route('me.press-kits.show', $company->id), navigate: true);
|
|
}
|
|
|
|
public function with(): array
|
|
{
|
|
return [
|
|
'portals' => [
|
|
Portal::Presseecho->value => Portal::Presseecho->label(),
|
|
Portal::Businessportal24->value => Portal::Businessportal24->label(),
|
|
Portal::Both->value => Portal::Both->label(),
|
|
],
|
|
'types' => [
|
|
CompanyType::Company->value => CompanyType::Company->label(),
|
|
CompanyType::Agency->value => CompanyType::Agency->label(),
|
|
],
|
|
'countries' => (array) config('countries.items', []),
|
|
];
|
|
}
|
|
}; ?>
|
|
|
|
<div class="space-y-6">
|
|
{{-- ============== PAGE HEADER ============== --}}
|
|
<header class="page-header">
|
|
<div class="min-w-0">
|
|
<div class="flex items-center gap-3 mb-3 flex-nowrap whitespace-nowrap">
|
|
<span class="badge hub dot">{{ __('User Backend') }}</span>
|
|
<span class="eyebrow muted">{{ __('Mein Bereich · Firmen · Anlegen') }}</span>
|
|
</div>
|
|
<h1 class="text-[30px] font-bold tracking-[-0.6px] leading-[1.15] m-0 text-[color:var(--color-ink)]">
|
|
{{ __('Neue Firma anlegen') }}
|
|
</h1>
|
|
<p class="text-[12.5px] leading-[1.55] mt-2 m-0 max-w-[640px] text-[color:var(--color-ink-3)]">
|
|
{{ __('Lege Stammdaten und Portal-Zuordnung an. Die Firma steht sofort zur Verfügung — die redaktionelle Prüfung erfolgt erst bei der ersten Pressemitteilung.') }}
|
|
</p>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2 flex-shrink-0">
|
|
<flux:button variant="filled" icon="arrow-left" href="{{ route('me.press-kits.index') }}" wire:navigate>
|
|
{{ __('Zurück zur Liste') }}
|
|
</flux:button>
|
|
</div>
|
|
</header>
|
|
|
|
<form wire:submit.prevent="save" class="space-y-6">
|
|
<article class="panel">
|
|
<div class="panel-head">
|
|
<span class="section-eyebrow">{{ __('Stammdaten') }}</span>
|
|
</div>
|
|
<div class="p-5 grid gap-4 sm:grid-cols-2">
|
|
<flux:field class="sm:col-span-2">
|
|
<flux:input wire:model="name" :label="__('Firmenname')" required autofocus />
|
|
<flux:error name="name" />
|
|
</flux:field>
|
|
|
|
<flux:field>
|
|
<flux:select wire:model="portal" :label="__('Portal')" :placeholder="__('Bitte wählen…')" required>
|
|
@foreach ($portals as $value => $label)
|
|
<flux:select.option value="{{ $value }}">{{ $label }}</flux:select.option>
|
|
@endforeach
|
|
</flux:select>
|
|
<flux:error name="portal" />
|
|
</flux:field>
|
|
|
|
<flux:field>
|
|
<flux:select wire:model="type" :label="__('Typ')" required>
|
|
@foreach ($types as $value => $label)
|
|
<flux:select.option value="{{ $value }}">{{ $label }}</flux:select.option>
|
|
@endforeach
|
|
</flux:select>
|
|
<flux:error name="type" />
|
|
</flux:field>
|
|
|
|
<flux:field>
|
|
<flux:input wire:model="email" :label="__('E-Mail')" type="email" />
|
|
<flux:error name="email" />
|
|
</flux:field>
|
|
|
|
<flux:field>
|
|
<flux:input wire:model="phone" :label="__('Telefon')" />
|
|
<flux:error name="phone" />
|
|
</flux:field>
|
|
|
|
<flux:field class="sm:col-span-2">
|
|
<flux:input wire:model="website" :label="__('Website')" placeholder="https://..." />
|
|
<flux:error name="website" />
|
|
</flux:field>
|
|
|
|
<flux:field class="sm:col-span-2">
|
|
<flux:textarea wire:model="address" :label="__('Adresse')" rows="3" />
|
|
<flux:error name="address" />
|
|
</flux:field>
|
|
|
|
<flux:field>
|
|
<flux:select wire:model="countryCode" :label="__('Land')">
|
|
@foreach ($countries as $code => $countryName)
|
|
<flux:select.option value="{{ $code }}">{{ $countryName }}</flux:select.option>
|
|
@endforeach
|
|
</flux:select>
|
|
<flux:error name="countryCode" />
|
|
</flux:field>
|
|
|
|
<flux:field class="sm:col-span-2">
|
|
<flux:checkbox wire:model="disableFooterCode" :label="__('Footer-Code deaktivieren (z. B. wenn die Firma keine Quellenangabe haben möchte)')" />
|
|
</flux:field>
|
|
</div>
|
|
</article>
|
|
|
|
<div class="flex items-center justify-end gap-2">
|
|
<flux:button variant="filled" href="{{ route('me.press-kits.index') }}" wire:navigate>
|
|
{{ __('Abbrechen') }}
|
|
</flux:button>
|
|
<flux:button type="submit" variant="primary" icon="check">
|
|
{{ __('Firma anlegen') }}
|
|
</flux:button>
|
|
</div>
|
|
</form>
|
|
</div>
|