80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Livewire;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use Livewire\WithFileUploads;
|
|
use Modules\Helpdesk\Models\Category;
|
|
use Modules\Helpdesk\Models\Priority;
|
|
use Modules\Helpdesk\Models\Project;
|
|
use Modules\Helpdesk\Services\TicketService;
|
|
|
|
final class TicketCreate extends Component
|
|
{
|
|
use WithFileUploads;
|
|
|
|
#[Validate('required|string|max:200')]
|
|
public string $subject = '';
|
|
|
|
#[Validate('required|string|min:10')]
|
|
public string $body = '';
|
|
|
|
#[Validate('required|integer|exists:helpdesk_priorities,id')]
|
|
public ?int $priority_id = null;
|
|
|
|
#[Validate('nullable|integer|exists:helpdesk_categories,id')]
|
|
public ?int $category_id = null;
|
|
|
|
#[Validate('nullable|integer|exists:helpdesk_projects,id')]
|
|
public ?int $project_id = null;
|
|
|
|
#[Validate('nullable|date')]
|
|
public ?string $due_at = null;
|
|
|
|
/** @var array<int, TemporaryUploadedFile> */
|
|
#[Validate('array')]
|
|
public array $attachments = [];
|
|
|
|
/**
|
|
* Store a new helpdesk ticket.
|
|
*
|
|
* @param TicketService $tickets
|
|
* @return mixed
|
|
*/
|
|
public function save(TicketService $tickets): mixed
|
|
{
|
|
$this->validate([
|
|
'attachments.*' => 'file|max:' . config('helpdesk.max_upload_kb') . '|mimes:' . implode(',', config('helpdesk.allowed_mimes')),
|
|
]);
|
|
|
|
$ticket = $tickets->create(Auth::user(), [
|
|
'subject' => $this->subject,
|
|
'body' => $this->body,
|
|
'priority_id' => $this->priority_id,
|
|
'category_id' => $this->category_id,
|
|
'project_id' => $this->project_id,
|
|
'due_at' => $this->due_at,
|
|
], $this->attachments);
|
|
|
|
session()->flash('success', 'Ticket ' . $ticket->reference . ' has been created.');
|
|
|
|
return $this->redirectRoute('helpdesk.tickets.show', $ticket, navigate: true);
|
|
}
|
|
|
|
/** @return View */
|
|
public function render(): View
|
|
{
|
|
return view('helpdesk::livewire.ticket-create', [
|
|
'priorities' => Priority::query()->orderBy('sort_order')->get(),
|
|
'categories' => Category::query()->orderBy('name')->get(),
|
|
'projects' => Project::query()->whereNull('archived_at')->orderBy('title')->get(),
|
|
])->layout('layouts.app');
|
|
}
|
|
}
|