diff --git a/Modules/Helpdesk/Livewire/TicketIndex.php b/Modules/Helpdesk/Livewire/TicketIndex.php index 2584ac92..bb0d5897 100644 --- a/Modules/Helpdesk/Livewire/TicketIndex.php +++ b/Modules/Helpdesk/Livewire/TicketIndex.php @@ -19,6 +19,13 @@ final class TicketIndex extends Component { use WithPagination; + + public bool $confirmingTicketDeletion = false; + + public ?int $ticketDeletionId = null; + + public ?string $ticketDeletionReference = null; + #[Url] public string $search = ''; @@ -79,4 +86,100 @@ 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; + + } } diff --git a/Modules/Helpdesk/Resources/views/livewire/ticket-index.blade.php b/Modules/Helpdesk/Resources/views/livewire/ticket-index.blade.php index 7cd1e310..6b8e3043 100644 --- a/Modules/Helpdesk/Resources/views/livewire/ticket-index.blade.php +++ b/Modules/Helpdesk/Resources/views/livewire/ticket-index.blade.php @@ -237,8 +237,7 @@ @can('delete', $ticket) + + + + + + @endif