Skip to content

Commit 1f6f22a

Browse files
committed
Add close ticket functionality
1 parent e009e7e commit 1f6f22a

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

app/Http/Controllers/Account/Support/TicketController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@
44

55
use App\Http\Controllers\Controller;
66
use App\Models\SupportTicket;
7+
use App\SupportTicket\Status;
78
use Illuminate\Http\Request;
89

910
class TicketController extends Controller
1011
{
1112
public static string $paginationLimit = '10';
1213

14+
public function closeTicket(SupportTicket $supportTicket)
15+
{
16+
$this->authorize('closeTicket', $supportTicket);
17+
18+
$supportTicket->update([
19+
'status' => Status::CLOSED,
20+
]);
21+
22+
return redirect()
23+
->route('support.tickets.show', $supportTicket)
24+
->with('success', __('account.support_ticket.close_ticket.success'));
25+
}
26+
1327
public function index()
1428
{
1529
$supportTickets = SupportTicket::whereUserId(auth()->user()->id)

app/Policies/SupportTicketPolicy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
class SupportTicketPolicy
1010
{
11+
public function closeTicket(User $user, SupportTicket $supportTicket): bool
12+
{
13+
return $supportTicket->user_id == $user->id;
14+
}
15+
1116
/**
1217
* Determine whether the user can view any models.
1318
*/

resources/views/support/tickets/show.blade.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
<x-layout-three-columns>
22
{{-- Desktop Buttons - Hidden on Mobile --}}
3-
<div class="hidden md:flex justify-end mb-4 space-x-3">
3+
<div class="hidden md:flex justify-between items-center mb-4">
44
<a href="/support/tickets" class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700">
55
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
66
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
77
</svg>
88
Back to Tickets
99
</a>
10-
<button type="button" class="inline-flex items-center px-4 py-2 text-sm font-medium text-violet-700 bg-violet-100 border border-violet-200 rounded-lg hover:bg-violet-200 dark:bg-violet-900/30 dark:text-violet-300 dark:border-violet-800 dark:hover:bg-violet-900/50">
11-
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
12-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/>
13-
</svg>
14-
Reply
15-
</button>
16-
<button type="button" class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700">
17-
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
18-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
19-
</svg>
20-
Close Ticket
21-
</button>
10+
<div class="flex space-x-3">
11+
@if($supportTicket->status !== \App\SupportTicket\Status::CLOSED)
12+
<button type="button" class="inline-flex items-center px-4 py-2 text-sm font-medium text-violet-700 bg-violet-100 border border-violet-200 rounded-lg hover:bg-violet-200 dark:bg-violet-900/30 dark:text-violet-300 dark:border-violet-800 dark:hover:bg-violet-900/50">
13+
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
14+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/>
15+
</svg>
16+
Reply
17+
</button>
18+
19+
<button type="button" onclick="document.getElementById('closeTicketForm').submit()" class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700">
20+
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
21+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
22+
</svg>
23+
Close Ticket
24+
</button>
25+
@endif
26+
</div>
2227
</div>
2328
<section class="mt-6">
2429
<div class="rounded-lg bg-white shadow dark:bg-gray-800">
@@ -63,7 +68,7 @@
6368
</p>
6469
</div>
6570
</section>
66-
71+
6772
{{-- Mobile Footer - Visible only on Mobile --}}
6873
<div class="md:hidden fixed bottom-0 left-0 right-0 bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 p-3 flex justify-between z-50">
6974
<a href="/support/tickets" class="flex-1 inline-flex items-center justify-center px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700 mx-1">
@@ -85,7 +90,12 @@
8590
Close
8691
</button>
8792
</div>
88-
93+
8994
{{-- Add padding at the bottom to prevent content from being hidden behind the mobile footer --}}
9095
<div class="md:hidden h-16"></div>
96+
97+
{{-- Close ticket form --}}
98+
<form action="{{ route('support.tickets.close', $supportTicket) }}" method="POST" id="closeTicketForm">
99+
@csrf
100+
</form>
91101
</x-layout-three-columns>

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373

7474
Route::get('/{supportTicket}', [TicketController::class, 'show'])
7575
->name('support.tickets.show');
76+
77+
Route::post('/{supportTicket}/close', [TicketController::class, 'closeTicket'])
78+
->name('support.tickets.close');
7679
});
7780
});
7881

0 commit comments

Comments
 (0)