Files
servicedesk/src/app/Livewire/Client/NewTicket.php
Kacper 90fae0a4de v1.1.0
- In-app notifications: a bell in the top bar backed by Laravel's database
  notification channel, alongside existing e-mail notifications (same
  per-trigger toggle drives both; ticket links now correctly point into the
  recipient's own area instead of always linking to the client view).
- Drag-and-drop attachments on every upload form, plus inline image
  thumbnails in the message thread instead of a plain download link.
- Customer satisfaction (CSAT) rating: clients rate a closed ticket 1-5 stars
  with an optional comment; shown read-only to operators, surfaced as a KPI
  on the stats dashboard, and linked from the "ticket closed" e-mail.
- Saved queue views: operators can save/apply/delete named filter+sort+
  column presets in the ticket queue and mark one as their default.
- Full-text search (MySQL FULLTEXT, portable LIKE fallback) across ticket
  subject/body and reply message bodies, now also on the client's own ticket
  list.
- Stats CSV export for the currently filtered ticket set.
- Optional BookStack knowledge-base integration (off by default): suggests
  articles by category/subcategory while creating a ticket and in a separate
  sidebar for operators on an existing ticket (with a copy-link button).
  Configurable connection/SSL bypass/search-type filter, plus two
  independent per-shelf allow-lists so nothing is ever searched until an
  admin opts specific shelves in.
- Closed tickets no longer show in "Moje zgłoszenia"/"Nieprzypisane"/team
  queue tabs, only under "Zamknięte" (matching how "Otwarte" already worked).
- Wired up the Admin > About "Wersja" field to config('app.version')/VERSION
  in .env instead of a stale hardcoded string.
- Fixed: TicketService::setStatus() now checks a status's stage rather than
  the literal key 'closed' to decide whether to fire the "ticket closed"
  notification/stop the timer.
- Updated README/ARCHITECTURE/CHANGELOG/install/SECURITY docs and all three
  wiki/ role guides for the above; documented a root-vs-www-data file
  ownership gotcha in CLAUDE.md (running artisan commands via a plain
  `docker exec` can leave root-owned Blade cache files that later break
  recompilation for the www-data Apache process).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-22 15:18:09 +02:00

136 lines
3.3 KiB
PHP

<?php
namespace App\Livewire\Client;
use App\Models\Category;
use App\Models\Subcategory;
use App\Services\BookStackClient;
use App\Services\TicketService;
use App\Support\Settings;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Livewire\WithFileUploads;
class NewTicket extends Component
{
use WithFileUploads;
public int $step = 1;
public ?int $categoryId = null;
public ?int $subcategoryId = null;
public string $subject = '';
public string $body = '';
public array $customValues = [];
public array $attachments = [];
#[Computed]
public function categories()
{
return Category::query()->with('subcategories')->get();
}
#[Computed]
public function selectedCategory(): ?Category
{
return $this->categoryId ? Category::query()->with('subcategories')->find($this->categoryId) : null;
}
#[Computed]
public function selectedSubcategory(): ?Subcategory
{
return $this->subcategoryId ? Subcategory::query()->with('customFields')->find($this->subcategoryId) : null;
}
public function selectCategory(int $id): void
{
$this->categoryId = $id;
$this->subcategoryId = null;
$this->step = 2;
}
public function selectSubcategory(int $id): void
{
$this->subcategoryId = $id;
$this->step = 3;
}
/**
* @return array<int, array{name: string, url: ?string}>
*/
#[Computed]
public function suggestedArticles(): array
{
$query = trim(($this->selectedCategory?->name ?? '').' '.($this->selectedSubcategory?->name ?? ''));
return app(BookStackClient::class)->search($query);
}
public function backToCategory(): void
{
$this->step = 1;
}
public function backToSubcategory(): void
{
$this->step = 2;
}
public function updatedAttachments(): void
{
if (! $this->attachments) {
return;
}
if ($error = Settings::validateAttachments($this->attachments)) {
$this->attachments = [];
$this->addError('attachments', $error);
}
}
public function removeAttachment(int $index): void
{
unset($this->attachments[$index]);
$this->attachments = array_values($this->attachments);
}
public function submit(): void
{
$rules = [
'subject' => 'required|string|max:255',
'body' => 'required|string',
];
foreach ($this->selectedSubcategory?->customFields ?? [] as $field) {
$rules["customValues.{$field->id}"] = $field->required ? 'required' : 'nullable';
}
$this->validate($rules);
$user = Auth::user();
$ticket = app(TicketService::class)->create([
'email' => $user->email,
'subcategory_id' => $this->subcategoryId,
'subject' => $this->subject,
'body' => $this->body,
'custom_values' => $this->customValues,
], $user);
app(TicketService::class)->attachFiles($ticket, $ticket->messages()->first(), $this->attachments);
$this->redirect(route('client.ticket', $ticket), navigate: true);
}
public function render()
{
return view('livewire.client.new-ticket');
}
}