Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
107 lines
4.9 KiB
PHP
107 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Communication\Inquiries\Pages;
|
|
|
|
use App\Domain\Communication\CommunicationAccess;
|
|
use App\Domain\Communication\Inquiry;
|
|
use App\Domain\Communication\InquiryNote;
|
|
use App\Domain\Communication\InquiryStatus;
|
|
use App\Filament\Resources\Communication\Inquiries\InquiryResource;
|
|
use App\Jobs\SendInquiryNotification;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
class ViewInquiry extends ViewRecord
|
|
{
|
|
protected static string $resource = InquiryResource::class;
|
|
|
|
public function getTitle(): string|Htmlable
|
|
{
|
|
/** @var Inquiry $inquiry */
|
|
$inquiry = $this->getRecord();
|
|
|
|
return $inquiry->contactTitle();
|
|
}
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
/** @var Inquiry $inquiry */
|
|
$inquiry = $this->getRecord();
|
|
|
|
return 'Anfrage '.$inquiry->reference.' vom '.$inquiry->created_at->format('d.m.Y H:i');
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('status')
|
|
->label('Status ändern')
|
|
->icon('heroicon-o-arrow-path')
|
|
->modalHeading('Bearbeitungsstatus')
|
|
->modalSubmitActionLabel('Status speichern')
|
|
->fillForm(fn (): array => ['status' => $this->getRecord()->status->value])
|
|
->schema([Select::make('status')->label('Neuer Status')->options(InquiryStatus::options())->required()])
|
|
->action(function (array $data): void {
|
|
$this->getRecord()->forceFill(['status' => $data['status']])->save();
|
|
Notification::make()->title('Der Status ist geändert.')->success()->send();
|
|
$this->refreshFormData(['status']);
|
|
}),
|
|
Action::make('note')
|
|
->label('Notiz hinzufügen')
|
|
->icon('heroicon-o-pencil-square')
|
|
->color('gray')
|
|
->modalHeading('Interne Notiz')
|
|
->modalDescription('Nur für das Team sichtbar, nie für den Anfragenden.')
|
|
->modalSubmitActionLabel('Notiz speichern')
|
|
->schema([Textarea::make('body')->label('Notiz')->required()->rows(4)->maxLength(4000)])
|
|
->action(function (array $data): void {
|
|
InquiryNote::query()->create([
|
|
'inquiry_id' => $this->getRecord()->id,
|
|
'user_id' => CommunicationAccess::user()?->id,
|
|
'body' => $data['body'],
|
|
]);
|
|
|
|
$this->getRecord()->load('notes');
|
|
Notification::make()->title('Die Notiz ist gespeichert.')->success()->send();
|
|
$this->redirect(InquiryResource::getUrl('view', ['record' => $this->getRecord()]));
|
|
}),
|
|
Action::make('resend')
|
|
->label('Benachrichtigung erneut senden')
|
|
->icon('heroicon-o-envelope')
|
|
->color('gray')
|
|
->visible(fn (): bool => $this->getRecord()->notified_at === null)
|
|
->requiresConfirmation()
|
|
->modalDescription('Sendet die interne Benachrichtigung an die in den Einstellungen hinterlegten Empfänger noch einmal.')
|
|
->action(function (): void {
|
|
SendInquiryNotification::dispatchSync($this->getRecord()->id);
|
|
$inquiry = $this->getRecord()->fresh();
|
|
|
|
if ($inquiry->notified_at !== null) {
|
|
Notification::make()->title('Die Benachrichtigung ist gesendet.')->success()->send();
|
|
} else {
|
|
Notification::make()->title('Die Benachrichtigung ist weiterhin fehlgeschlagen.')->body((string) $inquiry->notification_error)->danger()->send();
|
|
}
|
|
|
|
$this->redirect(InquiryResource::getUrl('view', ['record' => $inquiry]));
|
|
}),
|
|
Action::make('erase')
|
|
->label('Anfrage löschen')
|
|
->icon('heroicon-o-trash')
|
|
->color('danger')
|
|
->visible(fn (): bool => CommunicationAccess::erase())
|
|
->requiresConfirmation()
|
|
->modalHeading('Anfrage endgültig löschen?')
|
|
->modalDescription('Die Anfrage mit allen Antworten und Notizen wird unwiderruflich gelöscht, zum Beispiel auf Wunsch der betroffenen Person. Das lässt sich nicht rückgängig machen.')
|
|
->action(function (): void {
|
|
$this->getRecord()->delete();
|
|
Notification::make()->title('Die Anfrage ist gelöscht.')->success()->send();
|
|
$this->redirect(InquiryResource::getUrl('index'));
|
|
}),
|
|
];
|
|
}
|
|
}
|