user()?->can('feedback.send') ?? false; } protected static ?string $slug = 'rueckmeldung'; public string $type = ''; public string $subject = ''; public string $body = ''; public string $severity = 'normal'; public string $email = ''; public string $name = ''; public ?string $lastReference = null; public ?string $notice = null; public function mount(FeedbackChannels $channels): void { $this->type = (string) array_key_first($channels->available()); } public function submit(FeedbackChannels $channels, FeedbackOutbox $outbox, TechnicalInfo $info): void { $available = $channels->available(); $this->validate([ 'type' => ['required', 'in:'.implode(',', array_keys($available))], 'subject' => ['required', 'string', 'max:255'], 'body' => ['required', 'string', 'min:10', 'max:20000'], 'severity' => ['required', 'in:low,normal,high,critical'], 'email' => ['nullable', 'email', 'max:255'], 'name' => ['nullable', 'string', 'max:255'], ], attributes: [ 'type' => 'Art der Meldung', 'subject' => 'Betreff', 'body' => 'Beschreibung', 'email' => 'E-Mail-Adresse', 'name' => 'Name', ]); $this->notice = null; $this->lastReference = null; $payload = array_filter([ 'title' => $this->subject, 'body' => $this->body, 'email' => $this->email ?: null, 'name' => $this->name ?: null, 'severity' => $this->type === 'bugreport' ? $this->severity : null, ...$info->collect(), ], fn ($value) => $value !== null); $result = $outbox->submit(auth()->user(), $this->type, $payload); switch ($result->status) { case FeedbackResult::SENT: Audit::log('feedback.sent', ['type' => $this->type, 'reference' => $result->reference]); $this->lastReference = $result->reference; $this->reset(['subject', 'body', 'severity']); Notification::make()->success()->title('Vielen Dank – Ihre Meldung ist eingegangen')->body("Referenznummer: {$result->reference}")->persistent()->send(); break; case FeedbackResult::RETRY: $this->reset(['subject', 'body', 'severity']); $this->notice = 'Der Server ist gerade nicht erreichbar. Ihre Meldung ist gespeichert und wird automatisch gesendet, sobald es wieder geht. Die Referenznummer erscheint dann unten in der Liste.'; break; case FeedbackResult::INVALID: // Fehler direkt am betroffenen Feld anzeigen (API-Feld „title“ = Formularfeld „subject“). foreach ($result->errors as $field => $message) { $field = $field === 'title' ? 'subject' : $field; $this->addError(in_array($field, ['subject', 'body', 'email', 'name', 'severity'], true) ? $field : 'body', $message); } if ($result->errors === []) { $this->addError('body', $result->message ?? 'Die Eingabe ist unvollständig.'); } break; case FeedbackResult::RATE_LIMITED: $minutes = $result->retryAfter ? max(1, (int) ceil($result->retryAfter / 60)) : null; $this->notice = 'Es wurden zu viele Meldungen in kurzer Zeit gesendet. Bitte versuchen Sie es '.($minutes ? "in etwa {$minutes} Minute(n)" : 'später').' noch einmal – Ihre Eingabe bleibt erhalten.'; break; case FeedbackResult::DISABLED: $channels->disable($this->type); $this->notice = 'Dieser Meldeweg steht nicht mehr zur Verfügung. Ihre Eingabe bleibt erhalten'.(count($channels->available()) ? ' – bitte wählen Sie eine andere Art der Meldung.' : '.'); $this->type = (string) array_key_first($channels->available()); break; } } /** * @return array */ protected function getViewData(): array { return [ 'types' => app(FeedbackChannels::class)->available(), 'technical' => app(TechnicalInfo::class)->collect(), 'hasLicense' => app(LicenseStore::class)->hasLicense(), 'history' => VendorFeedback::query()->where('user_id', auth()->id())->latest()->limit(20)->get(), ]; } }