workign comments strucuture
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Helpdesk\Models\Comment;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'guid')) {
|
||||
$table->uuid('guid')->nullable()->after('id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'unid')) {
|
||||
$table->string('unid', 64)->nullable()->after('guid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'replica_id')) {
|
||||
$table->string('replica_id', 64)->nullable()->after('unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'parent_unid')) {
|
||||
$table->string('parent_unid', 64)->nullable()->after('parent_id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'root_unid')) {
|
||||
$table->string('root_unid', 64)->nullable()->after('parent_unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'originator_id')) {
|
||||
$table->string('originator_id', 96)->nullable()->after('root_unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'sync_sequence')) {
|
||||
$table->unsignedBigInteger('sync_sequence')->default(1)->after('originator_id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'sync_hash')) {
|
||||
$table->string('sync_hash', 128)->nullable()->after('sync_sequence');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'source_system')) {
|
||||
$table->string('source_system', 80)->default('wms-helpdesk')->after('sync_hash');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'source_record_id')) {
|
||||
$table->string('source_record_id', 120)->nullable()->after('source_system');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'body_text')) {
|
||||
$table->text('body_text')->nullable()->after('body');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'replicated_at')) {
|
||||
$table->timestamp('replicated_at')->nullable()->after('updated_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'synced_at')) {
|
||||
$table->timestamp('synced_at')->nullable()->after('replicated_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) {
|
||||
$table->timestamp('tombstoned_at')->nullable()->after('synced_at');
|
||||
}
|
||||
});
|
||||
|
||||
Comment::query()->orderBy('id')->chunkById(100, static function ($comments): void {
|
||||
foreach ($comments as $comment) {
|
||||
$guid = $comment->guid ?: (string) Str::uuid();
|
||||
$unid = $comment->unid ?: strtoupper(hash('sha256', $guid.'|'.$comment->ticket_id.'|'.$comment->id));
|
||||
$parent = $comment->parent_id ? Comment::query()->find($comment->parent_id) : null;
|
||||
$parentUnid = $parent?->unid;
|
||||
$rootUnid = $parent?->root_unid ?: $parentUnid ?: $unid;
|
||||
|
||||
DB::table('helpdesk_comments')
|
||||
->where('id', $comment->id)
|
||||
->update([
|
||||
'guid' => $guid,
|
||||
'unid' => $unid,
|
||||
'parent_unid' => $parentUnid,
|
||||
'root_unid' => $rootUnid,
|
||||
'originator_id' => $comment->originator_id ?: $unid.':1',
|
||||
'sync_sequence' => $comment->sync_sequence ?: 1,
|
||||
'sync_hash' => hash('sha256', (string) $comment->body),
|
||||
'body_text' => trim(strip_tags((string) $comment->body)),
|
||||
'source_system' => $comment->source_system ?: 'wms-helpdesk',
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->unique('guid', 'helpdesk_comments_guid_unique');
|
||||
$table->unique('unid', 'helpdesk_comments_unid_unique');
|
||||
$table->index(['ticket_id', 'root_unid', 'parent_unid'], 'helpdesk_comments_lotus_thread_index');
|
||||
$table->index(['ticket_id', 'is_internal', 'created_at'], 'helpdesk_comments_visibility_index');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->dropUnique('helpdesk_comments_guid_unique');
|
||||
$table->dropUnique('helpdesk_comments_unid_unique');
|
||||
$table->dropIndex('helpdesk_comments_lotus_thread_index');
|
||||
$table->dropIndex('helpdesk_comments_visibility_index');
|
||||
|
||||
$table->dropColumn([
|
||||
'guid',
|
||||
'unid',
|
||||
'replica_id',
|
||||
'parent_unid',
|
||||
'root_unid',
|
||||
'originator_id',
|
||||
'sync_sequence',
|
||||
'sync_hash',
|
||||
'source_system',
|
||||
'source_record_id',
|
||||
'body_text',
|
||||
'replicated_at',
|
||||
'synced_at',
|
||||
'tombstoned_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Helpdesk\Models\CannedResponse;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
@@ -56,6 +57,8 @@ final class TicketCommentStoreController extends Controller
|
||||
$body = trim($renderer->render($response->body, $ticket, $user));
|
||||
}
|
||||
|
||||
$body = $this->normaliseHtmlBody($body);
|
||||
|
||||
validator(['commentBody' => $body], [
|
||||
'commentBody' => ['required', 'string', 'min:2'],
|
||||
])->validate();
|
||||
@@ -67,7 +70,7 @@ final class TicketCommentStoreController extends Controller
|
||||
ticket: $ticket,
|
||||
user: $user,
|
||||
body: $body,
|
||||
internal: (bool) ($validated['internal'] ?? false),
|
||||
internal: (bool) ($validated['internal'] ?? false) && $this->userCanCreateInternalNote($user),
|
||||
files: $uploadedFiles,
|
||||
parentId: filled($validated['parent_id'] ?? null) ? (int) $validated['parent_id'] : null,
|
||||
);
|
||||
@@ -76,4 +79,31 @@ final class TicketCommentStoreController extends Controller
|
||||
->route('helpdesk.tickets.show', $ticket)
|
||||
->with('ticket-comment-added', filled($validated['parent_id'] ?? null) ? 'Reply posted.' : 'Comment posted.');
|
||||
}
|
||||
/**
|
||||
* Keep supported formatting tags but strip scripts and unsafe inline handlers.
|
||||
*/
|
||||
private function normaliseHtmlBody(string $body): string
|
||||
{
|
||||
$body = preg_replace('/<\s*(script|style)[^>]*>.*?<\s*\/\s*\1\s*>/is', '', $body) ?: '';
|
||||
$body = preg_replace('/\s+on[a-z]+\s*=\s*("[^"]*"|\'[^\']*\'|[^\s>]+)/i', '', $body) ?: '';
|
||||
$body = preg_replace('/javascript\s*:/i', '', $body) ?: '';
|
||||
|
||||
return trim(strip_tags($body, '<p><br><strong><b><em><i><u><ul><ol><li><blockquote><pre><code><a>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal notes are restricted to MPBA/core-company users.
|
||||
*/
|
||||
private function userCanCreateInternalNote(mixed $user): bool
|
||||
{
|
||||
$company = $user?->company;
|
||||
|
||||
if ($company === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) ($company->is_system_company ?? false)
|
||||
|| Str::lower((string) ($company->slug ?? '')) === 'mpba-limited'
|
||||
|| Str::contains(Str::lower((string) ($company->name ?? '')), 'mpba');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
@@ -302,6 +303,9 @@ final class TicketShow extends Component
|
||||
|
||||
$comments = Comment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->when(! $this->canSeeInternalNotes(), static function ($query): void {
|
||||
$query->where('is_internal', false);
|
||||
})
|
||||
->with(['user.company', 'attachments'])
|
||||
->oldest()
|
||||
->get();
|
||||
@@ -381,6 +385,22 @@ final class TicketShow extends Component
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* MPBA/core-company users can see internal notes. Other tenants only see public comments.
|
||||
*/
|
||||
private function canSeeInternalNotes(): bool
|
||||
{
|
||||
$company = Auth::user()?->company;
|
||||
|
||||
if ($company === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) ($company->is_system_company ?? false)
|
||||
|| Str::lower((string) ($company->slug ?? '')) === 'mpba-limited'
|
||||
|| Str::contains(Str::lower((string) ($company->name ?? '')), 'mpba');
|
||||
}
|
||||
|
||||
private function buildCommentTree(Collection $grouped, ?int $parentId = null): Collection
|
||||
{
|
||||
return $grouped->get($parentId, collect())->map(function ($comment) use ($grouped) {
|
||||
|
||||
@@ -14,10 +14,36 @@ final class Comment extends Model
|
||||
protected $table = 'helpdesk_comments';
|
||||
|
||||
/** @var list<string> */
|
||||
protected $fillable = ['ticket_id', 'parent_id', 'user_id', 'body', 'is_internal'];
|
||||
protected $fillable = [
|
||||
'ticket_id',
|
||||
'parent_id',
|
||||
'user_id',
|
||||
'body',
|
||||
'body_text',
|
||||
'is_internal',
|
||||
'guid',
|
||||
'unid',
|
||||
'replica_id',
|
||||
'parent_unid',
|
||||
'root_unid',
|
||||
'originator_id',
|
||||
'sync_sequence',
|
||||
'sync_hash',
|
||||
'source_system',
|
||||
'source_record_id',
|
||||
'replicated_at',
|
||||
'synced_at',
|
||||
'tombstoned_at',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected $casts = ['is_internal' => 'boolean'];
|
||||
protected $casts = [
|
||||
'is_internal' => 'boolean',
|
||||
'sync_sequence' => 'integer',
|
||||
'replicated_at' => 'datetime',
|
||||
'synced_at' => 'datetime',
|
||||
'tombstoned_at' => 'datetime',
|
||||
];
|
||||
|
||||
/** @return BelongsTo<Ticket, Comment> */
|
||||
public function ticket(): BelongsTo
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
'resources/css/app.css',
|
||||
'resources/js/app.js',
|
||||
])
|
||||
@php
|
||||
$currentUser = auth()->user();
|
||||
$currentCompany = $currentUser?->company;
|
||||
$canSeeInternalNotes = (bool) ($currentCompany?->is_system_company ?? false)
|
||||
|| \Illuminate\Support\Str::lower((string) ($currentCompany?->slug ?? '')) === 'mpba-limited'
|
||||
|| \Illuminate\Support\Str::contains(\Illuminate\Support\Str::lower((string) ($currentCompany?->name ?? '')), 'mpba');
|
||||
$visibleCommentCount = $ticket->comments->count();
|
||||
@endphp
|
||||
<div class="hd-helpdesk-surface space-y-6" dusk="helpdesk-ticket-show">
|
||||
<div class="overflow-hidden rounded-3xl border border-zinc-200 bg-white shadow-sm dark:border-zinc-700 dark:bg-zinc-900">
|
||||
<div class="bg-gradient-to-br from-slate-950 via-slate-900 to-blue-950 px-6 py-7 text-white">
|
||||
@@ -71,13 +79,38 @@
|
||||
@endif
|
||||
|
||||
<section class="space-y-4">
|
||||
<h2 class="text-lg font-semibold text-zinc-900 dark:text-white">Conversation</h2>
|
||||
<details open class="overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-sm dark:border-zinc-700 dark:bg-zinc-900">
|
||||
<summary class="flex cursor-pointer list-none items-center justify-between gap-4 bg-gradient-to-r from-slate-950 via-slate-900 to-red-950 px-5 py-4 text-white marker:hidden">
|
||||
<div>
|
||||
<h2 class="flex items-center gap-2 text-lg font-extrabold">
|
||||
<i class="fa-solid fa-comments" aria-hidden="true"></i>
|
||||
Conversation
|
||||
</h2>
|
||||
<p class="mt-1 text-sm font-medium text-red-50/85">Lotus Notes-style document responses and responses to responses.</p>
|
||||
</div>
|
||||
<span class="inline-flex items-center gap-2 rounded-full bg-white/15 px-3 py-1 text-xs font-extrabold ring-1 ring-white/20">
|
||||
{{ $visibleCommentCount }} item{{ $visibleCommentCount === 1 ? '' : 's' }}
|
||||
<i class="fa-solid fa-chevron-right transition group-open:rotate-90" aria-hidden="true"></i>
|
||||
</span>
|
||||
</summary>
|
||||
|
||||
@if ($ticket->comments->isNotEmpty())
|
||||
@include('helpdesk::partials.comment-thread', ['comments' => $ticket->comments, 'level' => 0, 'ticket' => $ticket])
|
||||
@else
|
||||
<div class="rounded-2xl border border-dashed border-zinc-300 p-8 text-center text-zinc-500 dark:border-zinc-700">No responses yet.</div>
|
||||
@endif
|
||||
<div class="space-y-4 p-5">
|
||||
<div class="grid gap-3 md:grid-cols-[1fr_auto]">
|
||||
<label class="sr-only" for="helpdesk-comment-search">Search comments</label>
|
||||
<input id="helpdesk-comment-search" type="search" placeholder="Search comments, GUID, UNID, author or text..." class="block w-full rounded-xl border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-900 shadow-sm focus:border-red-500 focus:ring-red-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100" data-helpdesk-comment-search>
|
||||
<button type="button" class="inline-flex items-center justify-center rounded-xl bg-red-600 px-4 py-2 text-sm font-bold text-white shadow-sm hover:bg-red-700" data-helpdesk-expand-comments>
|
||||
<i class="fa-solid fa-up-right-and-down-left-from-center mr-2" aria-hidden="true"></i>
|
||||
Expand all
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if ($ticket->comments->isNotEmpty())
|
||||
@include('helpdesk::partials.comment-thread', ['comments' => $ticket->comments, 'level' => 0, 'ticket' => $ticket, 'canSeeInternalNotes' => $canSeeInternalNotes])
|
||||
@else
|
||||
<div class="rounded-2xl border border-dashed border-zinc-300 p-8 text-center text-zinc-500 dark:border-zinc-700">No responses yet.</div>
|
||||
@endif
|
||||
</div>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<form method="POST" action="{{ route('helpdesk.tickets.comments.store', $ticket) }}" enctype="multipart/form-data" class="rounded-2xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-700 dark:bg-zinc-900" data-helpdesk-comment-form>
|
||||
@@ -116,19 +149,33 @@
|
||||
|
||||
<div>
|
||||
<label for="ticket-comment-body" class="mb-2 block text-sm font-medium text-zinc-700 dark:text-zinc-200">Comment</label>
|
||||
<textarea id="ticket-comment-body" dusk="ticket-comment-editor" name="commentBody" rows="5" placeholder="Write a professional response..." 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">{{ old('commentBody') }}</textarea>
|
||||
<div class="mb-2 flex flex-wrap gap-2" data-helpdesk-html-toolbar="ticket-comment-body">
|
||||
<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="u" class="rounded-lg border px-2 py-1 text-xs underline">U</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="ticket-comment-body" dusk="ticket-comment-editor" name="commentBody" rows="6" placeholder="Write a professional HTML response..." 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">{{ old('commentBody') }}</textarea>
|
||||
</div>
|
||||
|
||||
@can('update', $ticket)
|
||||
<label class="mt-4 flex items-center gap-2 text-sm font-semibold text-zinc-700 dark:text-zinc-200">
|
||||
<input type="checkbox" name="internal" value="1" @checked(old('internal')) class="rounded border-zinc-300">
|
||||
Internal note only
|
||||
</label>
|
||||
@if ($canSeeInternalNotes)
|
||||
<label class="mt-4 flex items-center gap-2 text-sm font-semibold text-zinc-700 dark:text-zinc-200">
|
||||
<input type="checkbox" name="internal" value="1" @checked(old('internal')) class="rounded border-zinc-300">
|
||||
MPBA internal note only
|
||||
</label>
|
||||
@endif
|
||||
@endcan
|
||||
|
||||
<div class="mt-4">
|
||||
<label class="mb-2 block text-sm font-medium text-zinc-700 dark:text-zinc-200">Attach files</label>
|
||||
<input name="attachments[]" type="file" multiple class="block w-full rounded-lg border border-zinc-300 bg-white p-2 text-sm dark:border-zinc-700 dark:bg-zinc-950" />
|
||||
<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>
|
||||
@error('attachments.*') <div class="mt-2 text-sm text-red-600">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
|
||||
@@ -149,7 +196,7 @@
|
||||
const select = form?.querySelector('[data-canned-response-select]');
|
||||
const textarea = form?.querySelector('textarea[name="commentBody"]');
|
||||
const selected = select?.selectedOptions?.[0];
|
||||
const body = selected?.dataset?.body || '';
|
||||
const body = decodeHtmlEntities(selected?.dataset?.body || '');
|
||||
|
||||
if (textarea && body.trim() !== '') {
|
||||
textarea.value = textarea.value.trim() === ''
|
||||
@@ -162,6 +209,29 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const toolbarButton = event.target.closest('[data-helpdesk-tag], [data-helpdesk-wrap]');
|
||||
|
||||
if (toolbarButton) {
|
||||
const toolbar = toolbarButton.closest('[data-helpdesk-html-toolbar]');
|
||||
const textarea = document.getElementById(toolbar?.dataset?.helpdeskHtmlToolbar || '');
|
||||
|
||||
if (textarea) {
|
||||
const tag = toolbarButton.dataset.helpdeskTag;
|
||||
const before = toolbarButton.dataset.helpdeskWrap || (tag === 'ul' ? '<ul><li>' : `<${tag}>`);
|
||||
const after = toolbarButton.dataset.helpdeskWrapEnd || (tag === 'ul' ? '</li></ul>' : `</${tag}>`);
|
||||
wrapSelection(textarea, before, after);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const expandButton = event.target.closest('[data-helpdesk-expand-comments]');
|
||||
|
||||
if (expandButton) {
|
||||
document.querySelectorAll('[data-helpdesk-comment-card]').forEach((card) => card.open = true);
|
||||
return;
|
||||
}
|
||||
|
||||
const replyButton = event.target.closest('[data-helpdesk-reply-toggle]');
|
||||
|
||||
if (! replyButton) {
|
||||
@@ -180,6 +250,47 @@
|
||||
target.querySelector('textarea')?.focus();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('input', function (event) {
|
||||
const search = event.target.closest('[data-helpdesk-comment-search]');
|
||||
|
||||
if (search) {
|
||||
const term = search.value.toLowerCase().trim();
|
||||
document.querySelectorAll('[data-helpdesk-comment-card]').forEach((card) => {
|
||||
const match = term === '' || (card.dataset.helpdeskCommentText || '').includes(term);
|
||||
card.classList.toggle('hidden', ! match);
|
||||
if (match) {
|
||||
card.open = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const fileInput = event.target.closest('[data-helpdesk-file-input]');
|
||||
|
||||
if (fileInput) {
|
||||
const label = fileInput.closest('div')?.querySelector('[data-helpdesk-file-label]');
|
||||
const count = fileInput.files?.length || 0;
|
||||
if (label) {
|
||||
label.textContent = count === 0 ? 'No files pinned' : `${count} file${count === 1 ? '' : 's'} pinned`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function decodeHtmlEntities(value) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.innerHTML = value;
|
||||
return textarea.value;
|
||||
}
|
||||
|
||||
function wrapSelection(textarea, before, after) {
|
||||
const start = textarea.selectionStart || 0;
|
||||
const end = textarea.selectionEnd || 0;
|
||||
const selected = textarea.value.substring(start, end) || 'text';
|
||||
textarea.value = textarea.value.substring(0, start) + before + selected + after + textarea.value.substring(end);
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(start + before.length, start + before.length + selected.length);
|
||||
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@props(['comments', 'level' => 0, 'ticket' => null])
|
||||
@props(['comments', 'level' => 0, 'ticket' => null, 'canSeeInternalNotes' => false])
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="space-y-3" data-helpdesk-thread-level="{{ (int) $level }}">
|
||||
@foreach ($comments as $comment)
|
||||
@php
|
||||
$commentUser = $comment->relationLoaded('user') ? $comment->getRelation('user') : null;
|
||||
@@ -8,68 +8,127 @@
|
||||
$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';
|
||||
@endphp
|
||||
|
||||
<div class="rounded-2xl border border-zinc-200 bg-white p-4 shadow-sm dark:border-zinc-700 dark:bg-zinc-900" style="margin-left: {{ min((int) $level, 4) * 1.25 }}rem">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="font-medium text-zinc-900 dark:text-zinc-100">
|
||||
{{ $commentUser?->name ?? 'Unknown user' }}
|
||||
@if (! $isInternal || $canSeeInternalNotes)
|
||||
<details open 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>
|
||||
<div class="text-xs text-zinc-500">
|
||||
{{ $comment->created_at?->format('d M Y H:i') }}
|
||||
|
||||
<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">
|
||||
{!! $comment->body !!}
|
||||
</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>
|
||||
|
||||
@if ($comment->is_internal)
|
||||
<span class="rounded-full bg-amber-100 px-2.5 py-1 text-xs font-bold text-amber-800 dark:bg-amber-950 dark:text-amber-100">Internal</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="prose prose-sm mt-3 max-w-none dark:prose-invert">
|
||||
{!! $comment->body !!}
|
||||
</div>
|
||||
|
||||
@if ($commentAttachments->isNotEmpty())
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
@foreach ($commentAttachments as $attachment)
|
||||
<a href="{{ route('helpdesk.attachments.download', $attachment->id) }}" target="_blank" class="rounded-lg border border-zinc-200 px-3 py-1 text-xs text-zinc-600 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-300 dark:hover:bg-zinc-800">
|
||||
{{ $attachment->original_name ?? $attachment->original_filename ?? $attachment->filename ?? $attachment->file_name ?? basename($attachment->path ?? $attachment->file_path ?? '') }}
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($currentTicket !== null)
|
||||
<div class="mt-3 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>
|
||||
Reply
|
||||
</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-blue-200 bg-blue-50 p-4 dark:border-blue-900 dark:bg-blue-950/40">
|
||||
@csrf
|
||||
<input type="hidden" name="parent_id" value="{{ $comment->id }}">
|
||||
<label for="reply-body-{{ $comment->id }}" class="mb-2 block text-sm font-medium text-zinc-700 dark:text-zinc-200">Reply</label>
|
||||
<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 reply..."></textarea>
|
||||
|
||||
<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 reply</button>
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
@if ($commentReplies->isNotEmpty())
|
||||
<div class="mt-4">
|
||||
@include('helpdesk::partials.comment-thread', [
|
||||
'comments' => $commentReplies,
|
||||
'level' => ((int) $level) + 1,
|
||||
'ticket' => $currentTicket,
|
||||
])
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</details>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Helpdesk\Models\Comment;
|
||||
use Modules\Helpdesk\Models\KanbanBoard;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
@@ -104,12 +105,33 @@ final class TicketService
|
||||
public function comment(Ticket $ticket, User $user, string $body, bool $internal = false, array $files = [], ?int $parentId = null): Comment
|
||||
{
|
||||
return DB::transaction(function () use ($ticket, $user, $body, $internal, $files, $parentId): Comment {
|
||||
$parent = $parentId === null
|
||||
? null
|
||||
: Comment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->findOrFail($parentId);
|
||||
|
||||
$guid = (string) Str::uuid();
|
||||
$unid = strtoupper(hash('sha256', $guid.'|'.$ticket->id.'|'.microtime(true)));
|
||||
$parentUnid = $parent?->unid;
|
||||
$rootUnid = $parent?->root_unid ?: $parentUnid ?: $unid;
|
||||
$plainTextBody = trim(preg_replace('/\s+/', ' ', strip_tags($body)) ?: '');
|
||||
|
||||
/** @var Comment $comment */
|
||||
$comment = $ticket->comments()->create([
|
||||
'parent_id' => $parentId,
|
||||
'user_id' => $user->id,
|
||||
'body' => $body,
|
||||
'body_text' => $plainTextBody,
|
||||
'is_internal' => $internal,
|
||||
'guid' => $guid,
|
||||
'unid' => $unid,
|
||||
'parent_unid' => $parentUnid,
|
||||
'root_unid' => $rootUnid,
|
||||
'originator_id' => $unid.':1',
|
||||
'sync_sequence' => 1,
|
||||
'sync_hash' => hash('sha256', $body),
|
||||
'source_system' => 'wms-helpdesk',
|
||||
]);
|
||||
|
||||
$ticket->forceFill(['last_activity_at' => now()])->save();
|
||||
|
||||
@@ -19,12 +19,14 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
|
||||
$fixtures = $this->seedLookupData();
|
||||
$user = $this->user(['name' => 'Ticket Browser User']);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $fixtures): void {
|
||||
$subject = 'Browser created helpdesk ticket '.uniqid();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $fixtures, $subject): void {
|
||||
$browser->loginAs($user)
|
||||
->visitRoute('helpdesk.tickets.create')
|
||||
->waitFor('@helpdesk-ticket-create')
|
||||
->assertSee('Create ticket')
|
||||
->type('@ticket-subject', 'Browser created helpdesk ticket');
|
||||
->type('@ticket-subject', $subject);
|
||||
|
||||
$this->setHelpdeskEditor($browser, 'ticket-body-editor', '<p>This browser ticket proves the form saves correctly.</p>');
|
||||
$this->setHelpdeskSelect($browser, 'board_id', $fixtures['board']->id);
|
||||
@@ -36,7 +38,7 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
|
||||
$browser->pause(500)
|
||||
->press('@ticket-create-submit')
|
||||
->waitFor('@helpdesk-ticket-index', 10)
|
||||
->assertSee('Browser created helpdesk ticket')
|
||||
->assertSee($subject)
|
||||
->assertSee('High')
|
||||
->assertSee('Support');
|
||||
});
|
||||
|
||||
@@ -65,6 +65,48 @@ final class TicketConversationTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function test_comment_post_endpoint_creates_lotus_identity_and_search_text(): void
|
||||
{
|
||||
$fixtures = $this->seedLookupData();
|
||||
$owner = $this->user();
|
||||
$ticket = $this->ticket(['owner' => $owner, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id]);
|
||||
|
||||
$this->actingAs($owner)
|
||||
->post(route('helpdesk.tickets.comments.store', $ticket), [
|
||||
'commentBody' => '<p><strong>Searchable response</strong></p>',
|
||||
])
|
||||
->assertRedirect(route('helpdesk.tickets.show', $ticket));
|
||||
|
||||
$comment = Comment::query()->where('ticket_id', $ticket->id)->firstOrFail();
|
||||
|
||||
self::assertNotEmpty($comment->guid);
|
||||
self::assertNotEmpty($comment->unid);
|
||||
self::assertSame($comment->unid, $comment->root_unid);
|
||||
self::assertSame('Searchable response', $comment->body_text);
|
||||
self::assertSame(1, $comment->sync_sequence);
|
||||
}
|
||||
|
||||
public function test_nested_reply_post_endpoint_preserves_lotus_parent_identity(): void
|
||||
{
|
||||
$fixtures = $this->seedLookupData();
|
||||
$owner = $this->user();
|
||||
$ticket = $this->ticket(['owner' => $owner, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id]);
|
||||
$parent = app(\Modules\Helpdesk\Services\TicketService::class)->comment($ticket, $owner, '<p>Parent response</p>');
|
||||
|
||||
$this->actingAs($owner)
|
||||
->post(route('helpdesk.tickets.comments.store', $ticket), [
|
||||
'parent_id' => $parent->id,
|
||||
'commentBody' => '<p>Child response</p>',
|
||||
])
|
||||
->assertRedirect(route('helpdesk.tickets.show', $ticket));
|
||||
|
||||
$reply = Comment::query()->where('parent_id', $parent->id)->firstOrFail();
|
||||
|
||||
self::assertSame($parent->unid, $reply->parent_unid);
|
||||
self::assertSame($parent->root_unid, $reply->root_unid);
|
||||
}
|
||||
|
||||
public function test_agent_can_update_status_to_closed_and_priority(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
@@ -213,3 +213,15 @@ versions:
|
||||
- Made Helpdesk settings section navigation use normal query-string links so Dusk and browsers do not depend on fragile Livewire tab clicks.
|
||||
- Updated browser tests to cover canned-response insertion, parent comment persistence, nested reply persistence and settings tab navigation.
|
||||
- Kept module.json version in sync with changelog.yaml.
|
||||
|
||||
"1.3.13":
|
||||
changed:
|
||||
- Added Lotus Notes-style collapsible ticket conversation cards with visible response counts, red threaded reply rails, search filtering and expand-all controls.
|
||||
- Added professional HTML helper controls for comments and nested responses while preserving safe HTML rendering.
|
||||
- Fixed canned-response insertion so stored HTML is inserted as real HTML instead of escaped text.
|
||||
- Added professional pinned attachment controls for root comments and response-to-response forms.
|
||||
- Restricted MPBA internal-note visibility and creation to MPBA/core-company users while hiding internal notes from ordinary tenant users.
|
||||
- Added GUID, UNID, parent UNID, root UNID, originator, sync sequence, sync hash and searchable body text fields to Helpdesk comments for future replication and search.
|
||||
- Updated TicketService comment creation to populate Lotus-style replication identity metadata for document responses and nested responses.
|
||||
- Updated Helpdesk conversation tests to cover POST comment storage, nested reply identity metadata and searchable comment text.
|
||||
- Kept module.json version in sync with changelog.yaml.
|
||||
|
||||
@@ -22,5 +22,5 @@
|
||||
"Modules\\Helpdesk\\Providers\\HelpdeskServiceProvider"
|
||||
],
|
||||
"files": [],
|
||||
"version": "1.3.12"
|
||||
"version": "1.3.13"
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ class PlatformAdministrationBrowserTest extends DuskTestCase
|
||||
$admin = $this->platformAdminUser();
|
||||
$this->seedPlatformDashboardData();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($admin): void {
|
||||
$companyName = 'Abbott Logistics '.uniqid();
|
||||
$billingEmail = 'billing+'.uniqid().'@abbott.example';
|
||||
|
||||
$this->browse(function (Browser $browser) use ($admin, $companyName, $billingEmail): void {
|
||||
$browser->loginAs($admin)
|
||||
->visit('/admin');
|
||||
|
||||
@@ -32,17 +35,20 @@ class PlatformAdministrationBrowserTest extends DuskTestCase
|
||||
{
|
||||
$admin = $this->platformAdminUser();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($admin): void {
|
||||
$companyName = 'Abbott Logistics '.uniqid();
|
||||
$billingEmail = 'billing+'.uniqid().'@abbott.example';
|
||||
|
||||
$this->browse(function (Browser $browser) use ($admin, $companyName, $billingEmail): void {
|
||||
$browser->loginAs($admin)
|
||||
->visit('/admin/companies');
|
||||
|
||||
$this->assertSingleProfessionalHeader($browser, 'Companies');
|
||||
$browser->type('name', 'Abbott Logistics Limited')
|
||||
->type('billing_email', 'billing@abbott.example')
|
||||
$browser->type('name', $companyName)
|
||||
->type('billing_email', $billingEmail)
|
||||
->select('status', 'active')
|
||||
->press('Create')
|
||||
->waitForText('Abbott Logistics Limited', 10)
|
||||
->assertSee('Abbott Logistics Limited');
|
||||
->waitForText($companyName, 10)
|
||||
->assertSee($companyName);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@ class WarehouseBrowserTest extends DuskTestCase
|
||||
$user = $this->tenantUser();
|
||||
$warehouse = $this->seedWarehouse($user->company);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $warehouse): void {
|
||||
$ruleName = 'Require expiry date '.uniqid();
|
||||
$ruleKey = 'expiry-required-'.uniqid();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $warehouse, $ruleName, $ruleKey): void {
|
||||
$browser->loginAs($user)
|
||||
->visit('/dashboard');
|
||||
|
||||
@@ -37,14 +40,14 @@ class WarehouseBrowserTest extends DuskTestCase
|
||||
$browser->assertSee('Require batch number')
|
||||
->assertSee('batch-required')
|
||||
->select('warehouse_id', (string) $warehouse->id)
|
||||
->type('name', 'Require expiry date')
|
||||
->type('rule_key', 'expiry-required')
|
||||
->type('name', $ruleName)
|
||||
->type('rule_key', $ruleKey)
|
||||
->select('severity', 'error')
|
||||
->type('configuration', '{"field":"expires_at"}')
|
||||
->press('Add rule')
|
||||
->waitForText('Require expiry date', 10)
|
||||
->assertSee('Require expiry date')
|
||||
->assertSee('expiry-required');
|
||||
->waitForText($ruleName, 10)
|
||||
->assertSee($ruleName)
|
||||
->assertSee($ruleKey);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,17 +55,20 @@ class WarehouseBrowserTest extends DuskTestCase
|
||||
{
|
||||
$user = $this->tenantUser();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user): void {
|
||||
$warehouseName = 'East Midlands DC '.uniqid();
|
||||
$warehouseCode = 'E'.substr(strtoupper(uniqid()), -4);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $warehouseName, $warehouseCode): void {
|
||||
$browser->loginAs($user)
|
||||
->visit('/warehouses');
|
||||
|
||||
$this->assertSingleProfessionalHeader($browser, 'Warehouses');
|
||||
$browser->type('code', 'EAST')
|
||||
->type('name', 'East Midlands DC')
|
||||
$browser->type('code', $warehouseCode)
|
||||
->type('name', $warehouseName)
|
||||
->type('address', 'Main Road, Nottingham')
|
||||
->press('Create')
|
||||
->waitForText('East Midlands DC', 10)
|
||||
->assertSee('East Midlands DC');
|
||||
->waitForText($warehouseName, 10)
|
||||
->assertSee($warehouseName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,19 +77,22 @@ class WarehouseBrowserTest extends DuskTestCase
|
||||
$user = $this->tenantUser();
|
||||
$warehouse = $this->seedWarehouse($user->company);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $warehouse): void {
|
||||
$ruleName = 'Require serial number '.uniqid();
|
||||
$ruleKey = 'serial-required-'.uniqid();
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user, $warehouse, $ruleName, $ruleKey): void {
|
||||
$browser->loginAs($user)
|
||||
->visit('/warehouse-rules');
|
||||
|
||||
$this->assertSingleProfessionalHeader($browser, 'Validation Rules');
|
||||
$browser->select('warehouse_id', (string) $warehouse->id)
|
||||
->type('name', 'Require serial number')
|
||||
->type('rule_key', 'serial-required')
|
||||
->type('name', $ruleName)
|
||||
->type('rule_key', $ruleKey)
|
||||
->select('severity', 'error')
|
||||
->type('configuration', '{"field":"serial_no"}')
|
||||
->press('Add rule')
|
||||
->waitForText('Require serial number', 10)
|
||||
->assertSee('serial-required');
|
||||
->waitForText($ruleName, 10)
|
||||
->assertSee($ruleKey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user