intial ticket fix partial delete fix
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Modules\Helpdesk\Livewire;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Url;
|
||||
@@ -17,9 +18,9 @@ use Modules\Helpdesk\Models\Ticket;
|
||||
|
||||
final class TicketIndex extends Component
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
use WithPagination;
|
||||
|
||||
|
||||
public bool $confirmingTicketDeletion = false;
|
||||
|
||||
public ?int $ticketDeletionId = null;
|
||||
@@ -38,17 +39,57 @@ final class TicketIndex extends Component
|
||||
#[Url]
|
||||
public string $scope = 'open';
|
||||
|
||||
/**
|
||||
* Reset pagination when filters change.
|
||||
*/
|
||||
public function updated(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the ticket list.
|
||||
* Open the delete confirmation modal for a visible ticket.
|
||||
*/
|
||||
public function confirmDeleteTicket(int $ticketId): void
|
||||
{
|
||||
$ticket = Ticket::query()
|
||||
->visibleTo(Auth::user())
|
||||
->findOrFail($ticketId);
|
||||
|
||||
$this->ticketDeletionId = $ticket->id;
|
||||
$this->ticketDeletionReference = $ticket->reference;
|
||||
$this->confirmingTicketDeletion = true;
|
||||
}
|
||||
|
||||
public function cancelDeleteTicket(): void
|
||||
{
|
||||
$this->resetTicketDeletionState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the confirmed ticket.
|
||||
*/
|
||||
public function deleteConfirmedTicket(): void
|
||||
{
|
||||
if ($this->ticketDeletionId === null) {
|
||||
$this->resetTicketDeletionState();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket = Ticket::query()
|
||||
->visibleTo(Auth::user())
|
||||
->findOrFail($this->ticketDeletionId);
|
||||
|
||||
$this->authorize('delete', $ticket);
|
||||
|
||||
$reference = $ticket->reference;
|
||||
|
||||
$ticket->delete();
|
||||
|
||||
$this->resetTicketDeletionState();
|
||||
$this->resetPage();
|
||||
|
||||
session()->flash('success', "Ticket {$reference} was deleted successfully.");
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('helpdesk::livewire.ticket-index', [
|
||||
@@ -58,9 +99,14 @@ final class TicketIndex extends Component
|
||||
])->layout('layouts.app');
|
||||
}
|
||||
|
||||
private function resetTicketDeletionState(): void
|
||||
{
|
||||
$this->confirmingTicketDeletion = false;
|
||||
$this->ticketDeletionId = null;
|
||||
$this->ticketDeletionReference = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build paginated ticket results.
|
||||
*
|
||||
* @return LengthAwarePaginator<int, Ticket>
|
||||
*/
|
||||
private function tickets(): LengthAwarePaginator
|
||||
@@ -85,101 +131,6 @@ final class TicketIndex extends Component
|
||||
})
|
||||
->latest('last_activity_at')
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Open the delete confirmation modal for a ticket.
|
||||
|
||||
*/
|
||||
|
||||
public function confirmDeleteTicket(int $ticketId): void
|
||||
|
||||
{
|
||||
|
||||
$ticket = Ticket::query()->findOrFail($ticketId);
|
||||
|
||||
$this->authorize('delete', $ticket);
|
||||
|
||||
$this->ticketDeletionId = $ticket->id;
|
||||
|
||||
$this->ticketDeletionReference = $ticket->reference;
|
||||
|
||||
$this->confirmingTicketDeletion = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Close the delete confirmation modal.
|
||||
|
||||
*/
|
||||
|
||||
public function cancelDeleteTicket(): void
|
||||
|
||||
{
|
||||
|
||||
$this->resetTicketDeletionState();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Delete the confirmed ticket.
|
||||
|
||||
*/
|
||||
|
||||
public function deleteConfirmedTicket(): void
|
||||
|
||||
{
|
||||
|
||||
if ($this->ticketDeletionId === null) {
|
||||
|
||||
$this->resetTicketDeletionState();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$ticket = Ticket::query()->findOrFail($this->ticketDeletionId);
|
||||
|
||||
$this->authorize('delete', $ticket);
|
||||
|
||||
$reference = $ticket->reference;
|
||||
|
||||
$ticket->delete();
|
||||
|
||||
$this->resetTicketDeletionState();
|
||||
|
||||
$this->resetPage();
|
||||
|
||||
$this->dispatch('wms:toast', [
|
||||
|
||||
'type' => 'success',
|
||||
|
||||
'title' => 'Ticket deleted',
|
||||
|
||||
'message' => "Ticket {$reference} was deleted successfully.",
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Reset ticket deletion modal state.
|
||||
|
||||
*/
|
||||
|
||||
private function resetTicketDeletionState(): void
|
||||
|
||||
{
|
||||
|
||||
$this->confirmingTicketDeletion = false;
|
||||
|
||||
$this->ticketDeletionId = null;
|
||||
|
||||
$this->ticketDeletionReference = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user