intial ticket fix partial delete fix
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,8 +237,7 @@
|
||||
@can('delete', $ticket)
|
||||
<button
|
||||
type="button"
|
||||
wire:click="deleteTicket({{ $ticket->id }})"
|
||||
wire:confirm="Delete ticket {{ $ticket->reference }}? This action cannot be undone."
|
||||
wire:click="confirmDeleteTicket({{ $ticket->id }})"
|
||||
class="hd-btn hd-btn-sm hd-btn-red"
|
||||
title="Delete {{ $ticket->reference }}"
|
||||
dusk="delete-ticket-{{ $ticket->id }}"
|
||||
@@ -262,4 +261,64 @@
|
||||
{{ $tickets->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@if ($confirmingTicketDeletion)
|
||||
<div
|
||||
class="fixed inset-0 z-[9998] flex items-center justify-center bg-black/70 px-4 py-6 backdrop-blur-sm"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="delete-ticket-modal-title"
|
||||
dusk="delete-ticket-confirmation-modal"
|
||||
>
|
||||
<div class="w-full max-w-lg overflow-hidden rounded-3xl border border-red-500/30 bg-zinc-950 text-zinc-100 shadow-2xl">
|
||||
<div class="border-b border-red-500/20 bg-red-950/40 px-6 py-5">
|
||||
<div class="flex items-start gap-4">
|
||||
<span class="grid h-12 w-12 shrink-0 place-items-center rounded-2xl bg-red-600 text-white shadow-lg shadow-red-950/40">
|
||||
<i class="fa-solid fa-triangle-exclamation" aria-hidden="true"></i>
|
||||
</span>
|
||||
|
||||
<div class="min-w-0">
|
||||
<h2 id="delete-ticket-modal-title" class="text-xl font-black tracking-tight text-white">
|
||||
Delete ticket?
|
||||
</h2>
|
||||
|
||||
<p class="mt-1 text-sm leading-6 text-red-100/90">
|
||||
This will delete <span class="font-mono font-bold">{{ $ticketDeletionReference }}</span>. This action cannot be undone.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-5">
|
||||
<p class="text-sm leading-6 text-zinc-300">
|
||||
Confirm only if this ticket was created in error or is no longer required. Related ticket data may also be removed depending on the model relationships.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col-reverse gap-3 border-t border-zinc-800 bg-zinc-900/80 px-6 py-4 sm:flex-row sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
wire:click="cancelDeleteTicket"
|
||||
class="hd-btn hd-btn-sm hd-btn-blue"
|
||||
dusk="cancel-delete-ticket"
|
||||
>
|
||||
<i class="fa-solid fa-xmark" aria-hidden="true"></i>
|
||||
<span>Cancel</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
wire:click="deleteConfirmedTicket"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="deleteConfirmedTicket"
|
||||
class="hd-btn hd-btn-sm hd-btn-red disabled:cursor-not-allowed disabled:opacity-60"
|
||||
dusk="confirm-delete-ticket"
|
||||
>
|
||||
<i class="fa-solid fa-trash" aria-hidden="true"></i>
|
||||
<span wire:loading.remove wire:target="deleteConfirmedTicket">Delete ticket</span>
|
||||
<span wire:loading wire:target="deleteConfirmedTicket">Deleting...</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user