new helpdesk module
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Livewire;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
use Modules\Helpdesk\Services\WorkflowNotificationService;
|
||||
|
||||
final class KanbanBoard extends Component
|
||||
{
|
||||
/**
|
||||
* Move a ticket to another workflow status.
|
||||
*
|
||||
* @param int $ticketId
|
||||
* @param int $statusId
|
||||
* @param WorkflowNotificationService $workflow
|
||||
* @return void
|
||||
*/
|
||||
public function moveTicket(int $ticketId, int $statusId, WorkflowNotificationService $workflow): void
|
||||
{
|
||||
$ticket = Ticket::query()->visibleTo(Auth::user())->findOrFail($ticketId);
|
||||
$status = Status::query()->findOrFail($statusId);
|
||||
|
||||
$oldStatus = $ticket->status?->name;
|
||||
|
||||
$ticket->forceFill([
|
||||
'status_id' => $status->id,
|
||||
'completed_at' => $status->is_closed ? now() : null,
|
||||
'last_activity_at' => now(),
|
||||
])->save();
|
||||
|
||||
$workflow->dispatch(
|
||||
$ticket->fresh(['owner', 'agent', 'status', 'priority', 'category', 'project', 'team']),
|
||||
$status->is_closed ? 'ticket_closed' : 'ticket_updated',
|
||||
Auth::user()
|
||||
);
|
||||
|
||||
session()->flash('success', 'Ticket moved to ' . $status->name . '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Kanban board.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('helpdesk::livewire.kanban-board', [
|
||||
'statuses' => Status::query()->orderBy('sort_order')->get(),
|
||||
'ticketsByStatus' => $this->ticketsByStatus(),
|
||||
])->layout('layouts.app');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get visible tickets grouped by status.
|
||||
*
|
||||
* @return array<int, Collection<int, Ticket>>
|
||||
*/
|
||||
private function ticketsByStatus(): array
|
||||
{
|
||||
return Ticket::query()
|
||||
->with(['owner', 'agent', 'status', 'priority', 'category', 'project', 'team'])
|
||||
->visibleTo(Auth::user())
|
||||
->latest('last_activity_at')
|
||||
->limit(200)
|
||||
->get()
|
||||
->groupBy('status_id')
|
||||
->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user