Files
WMS/Modules/Helpdesk/Resources/views/partials/comment-thread.blade.php
T
2026-06-17 10:48:14 +01:00

169 lines
13 KiB
PHP

@props(['comments', 'level' => 0, 'ticket' => null, 'canSeeInternalNotes' => false])
<div class="space-y-3" data-helpdesk-thread-level="{{ (int) $level }}">
@foreach ($comments as $comment)
@php
$commentUser = $comment->relationLoaded('user') ? $comment->getRelation('user') : null;
$commentAttachments = $comment->relationLoaded('attachments') ? $comment->getRelation('attachments') : collect();
$commentReplies = $comment->relationLoaded('replies') ? $comment->getRelation('replies') : collect();
$replyFormId = 'helpdesk-reply-form-'.$comment->id;
$currentTicket = $ticket ?? $comment->ticket ?? null;
$replyCount = $commentReplies->count();
$isInternal = (bool) $comment->is_internal;
$borderClass = $isInternal ? 'border-amber-300 dark:border-amber-700' : 'border-red-200 dark:border-red-900/70';
$railClass = $isInternal ? 'bg-amber-500' : 'bg-red-500';
$renderedBody = html_entity_decode((string) $comment->body, ENT_QUOTES | ENT_HTML5, 'UTF-8');
while (str_contains($renderedBody, '&lt;') || str_contains($renderedBody, '&gt;') || str_contains($renderedBody, '&amp;lt;')) {
$decodedBody = html_entity_decode($renderedBody, ENT_QUOTES | ENT_HTML5, 'UTF-8');
if ($decodedBody === $renderedBody) {
break;
}
$renderedBody = $decodedBody;
}
if ($currentTicket !== null) {
$renderedBody = strtr($renderedBody, [
'{{ ticket.reference }}' => (string) e((string) ($currentTicket->reference ?? '')),
'{{ ticket.subject }}' => (string) e((string) ($currentTicket->subject ?? '')),
'{{ ticket.status }}' => (string) e((string) ($currentTicket->status?->name ?? '')),
'{{ ticket.priority }}' => (string) e((string) ($currentTicket->priority?->name ?? '')),
'{{ ticket.category }}' => (string) e((string) ($currentTicket->category?->name ?? '')),
'{{ ticket.project }}' => (string) e((string) ($currentTicket->project?->title ?? '')),
'{{ ticket.team }}' => (string) e((string) ($currentTicket->team?->name ?? '')),
'{{ requester.name }}' => (string) e((string) ($currentTicket->owner?->name ?? $currentTicket->user?->name ?? '')),
'{{ agent.name }}' => (string) e((string) ($currentTicket->agent?->name ?? '')),
'{{ actor.name }}' => (string) e((string) ($commentUser?->name ?? '')),
'{{ ticket.url }}' => (string) e(route('helpdesk.tickets.show', ['ticket' => $currentTicket->getKey()])),
]);
}
$containsHtml = $renderedBody !== strip_tags($renderedBody);
$renderedBody = preg_replace('/<\s*(script|style)[^>]*>.*?<\s*\/\s*\1\s*>/is', '', $renderedBody) ?: '';
$renderedBody = preg_replace('/\s+on[a-z]+\s*=\s*("[^"]*"|\'[^\']*\'|[^\s>]+)/i', '', $renderedBody) ?: '';
$renderedBody = preg_replace('/javascript\s*:/i', '', $renderedBody) ?: '';
$renderedBody = strip_tags($renderedBody, '<p><br><strong><b><em><i><u><ul><ol><li><blockquote><pre><code><a>');
$renderedBody = $containsHtml ? $renderedBody : nl2br(e($renderedBody));
@endphp
@if (! $isInternal || $canSeeInternalNotes)
<details class="group rounded-2xl border {{ $borderClass }} bg-white shadow-sm transition dark:bg-zinc-900" data-helpdesk-comment-card data-helpdesk-comment-text="{{ e(Str::lower(strip_tags((string) $comment->body).' '.($comment->body_text ?? '').' '.($commentUser?->name ?? '').' '.($comment->unid ?? '').' '.($comment->guid ?? ''))) }}" style="margin-left: {{ min((int) $level, 4) * 1.25 }}rem">
<summary class="flex cursor-pointer list-none items-start gap-3 rounded-2xl p-4 marker:hidden">
<span class="mt-1 inline-flex h-12 w-2 shrink-0 rounded-full {{ $railClass }}" aria-hidden="true"></span>
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-2">
<span class="font-bold text-zinc-900 dark:text-zinc-100">{{ $commentUser?->name ?? 'Unknown user' }}</span>
<span class="text-xs font-semibold text-zinc-500">{{ $comment->created_at?->format('d M Y H:i') }}</span>
<span class="rounded-full bg-blue-100 px-2.5 py-1 text-[11px] font-extrabold text-blue-800 dark:bg-blue-950 dark:text-blue-100">{{ $replyCount }} response{{ $replyCount === 1 ? '' : 's' }}</span>
@if ($commentAttachments->isNotEmpty())
<span class="rounded-full bg-emerald-100 px-2.5 py-1 text-[11px] font-extrabold text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100">
<i class="fa-solid fa-paperclip mr-1" aria-hidden="true"></i>{{ $commentAttachments->count() }}
</span>
@endif
@if ($isInternal)
<span class="rounded-full bg-amber-100 px-2.5 py-1 text-[11px] font-extrabold text-amber-800 dark:bg-amber-950 dark:text-amber-100">MPBA internal</span>
@endif
</div>
<div class="mt-1 flex flex-wrap items-center gap-2 text-[11px] font-mono text-zinc-400">
@if (! blank($comment->unid))
<span>UNID {{ Str::limit((string) $comment->unid, 16, '') }}</span>
@endif
@if (! blank($comment->guid))
<span>GUID {{ Str::limit((string) $comment->guid, 18, '') }}</span>
@endif
</div>
</div>
<span class="mt-1 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-zinc-100 text-zinc-600 transition group-open:rotate-90 dark:bg-zinc-800 dark:text-zinc-200">
<i class="fa-solid fa-chevron-right text-xs" aria-hidden="true"></i>
</span>
</summary>
<div class="border-t border-zinc-100 px-4 pb-4 pt-3 dark:border-zinc-800">
<div class="prose prose-sm max-w-none dark:prose-invert">
{!! $renderedBody !!}
</div>
@if ($commentAttachments->isNotEmpty())
<div class="mt-4 rounded-xl border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-700 dark:bg-zinc-950/60">
<div class="mb-2 flex items-center gap-2 text-xs font-extrabold uppercase tracking-wide text-zinc-500">
<i class="fa-solid fa-paperclip text-blue-500" aria-hidden="true"></i>
Attachments
</div>
<div class="flex flex-wrap gap-2">
@foreach ($commentAttachments as $attachment)
<a href="{{ route('helpdesk.attachments.download', $attachment->id) }}" target="_blank" class="inline-flex items-center gap-2 rounded-lg border border-blue-200 bg-white px-3 py-2 text-xs font-bold text-blue-700 shadow-sm hover:bg-blue-50 dark:border-blue-900 dark:bg-zinc-900 dark:text-blue-200 dark:hover:bg-blue-950/50">
<i class="fa-solid fa-thumbtack" aria-hidden="true"></i>
{{ $attachment->original_name ?? $attachment->original_filename ?? $attachment->filename ?? $attachment->file_name ?? basename($attachment->path ?? $attachment->file_path ?? '') }}
</a>
@endforeach
</div>
</div>
@endif
@if ($currentTicket !== null)
<div class="mt-4 flex justify-end">
<button type="button" dusk="reply-to-comment-{{ $comment->id }}" data-helpdesk-reply-toggle="{{ $replyFormId }}" class="inline-flex items-center justify-center rounded-lg bg-blue-600 px-3 py-2 text-xs font-bold text-white shadow-sm transition hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400/70">
<i class="fa-solid fa-reply mr-2" aria-hidden="true"></i>
Respond
</button>
</div>
<form id="{{ $replyFormId }}" method="POST" action="{{ route('helpdesk.tickets.comments.store', $currentTicket) }}" enctype="multipart/form-data" class="mt-4 hidden rounded-xl border border-red-200 bg-red-50/60 p-4 dark:border-red-900 dark:bg-red-950/20" data-helpdesk-comment-form>
@csrf
<input type="hidden" name="parent_id" value="{{ $comment->id }}">
<label for="reply-body-{{ $comment->id }}" class="mb-2 block text-sm font-bold text-zinc-700 dark:text-zinc-200">Response to response</label>
<div class="mb-2 flex flex-wrap gap-2" data-helpdesk-html-toolbar="reply-body-{{ $comment->id }}">
<button type="button" data-helpdesk-tag="strong" class="rounded-lg border px-2 py-1 text-xs font-black">B</button>
<button type="button" data-helpdesk-tag="em" class="rounded-lg border px-2 py-1 text-xs italic">I</button>
<button type="button" data-helpdesk-tag="ul" class="rounded-lg border px-2 py-1 text-xs">List</button>
<button type="button" data-helpdesk-wrap="<blockquote>" data-helpdesk-wrap-end="</blockquote>" class="rounded-lg border px-2 py-1 text-xs">Quote</button>
<button type="button" data-helpdesk-wrap="<code>" data-helpdesk-wrap-end="</code>" class="rounded-lg border px-2 py-1 text-xs">Code</button>
</div>
<textarea id="reply-body-{{ $comment->id }}" dusk="reply-body-{{ $comment->id }}" name="commentBody" rows="4" required class="block w-full rounded-xl border border-zinc-300 bg-white p-3 text-sm text-zinc-900 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100" placeholder="Write a threaded Lotus Notes-style response..."></textarea>
@can('update', $currentTicket)
@if ($canSeeInternalNotes)
<label class="mt-3 flex items-center gap-2 text-sm font-semibold text-zinc-700 dark:text-zinc-200">
<input type="checkbox" name="internal" value="1" class="rounded border-zinc-300">
MPBA internal note only
</label>
@endif
@endcan
<div class="mt-4 rounded-xl border border-dashed border-blue-300 p-3 dark:border-blue-800">
<label class="inline-flex cursor-pointer items-center gap-2 rounded-lg bg-blue-600 px-3 py-2 text-xs font-bold text-white shadow-sm hover:bg-blue-700">
<i class="fa-solid fa-thumbtack" aria-hidden="true"></i>
Pin attachments
<input name="attachments[]" type="file" multiple class="sr-only" data-helpdesk-file-input>
</label>
<span class="ml-2 text-xs font-semibold text-zinc-500" data-helpdesk-file-label>No files pinned</span>
</div>
<div class="mt-4 flex justify-end gap-2">
<button type="button" data-helpdesk-reply-toggle="{{ $replyFormId }}" class="inline-flex items-center justify-center rounded-lg bg-slate-600 px-3 py-2 text-xs font-bold text-white shadow-sm transition hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400/70">Cancel</button>
<button type="submit" dusk="post-reply-{{ $comment->id }}" class="inline-flex items-center justify-center rounded-lg bg-emerald-600 px-3 py-2 text-xs font-bold text-white shadow-sm transition hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-emerald-400/70">Post response</button>
</div>
</form>
@endif
@if ($commentReplies->isNotEmpty())
<div class="mt-4 border-l-4 border-red-500 pl-4">
@include('helpdesk::partials.comment-thread', [
'comments' => $commentReplies,
'level' => ((int) $level) + 1,
'ticket' => $currentTicket,
'canSeeInternalNotes' => $canSeeInternalNotes,
])
</div>
@endif
</div>
</details>
@endif
@endforeach
</div>