425 lines
24 KiB
PHP
425 lines
24 KiB
PHP
@php
|
|
$helpdeskAttachmentAccept = collect(config('helpdesk.allowed_extensions', config('helpdesk.allowed_mimes', [])))
|
|
->filter(fn ($extension) => is_string($extension) && trim($extension) !== '')
|
|
->map(fn ($extension) => '.' . strtolower(ltrim(trim($extension), '.')))
|
|
->unique()
|
|
->implode(',');
|
|
@endphp
|
|
<div class="hd-helpdesk-surface space-y-6" dusk="helpdesk-ticket-create">
|
|
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
|
@include('helpdesk::partials.page-header', [
|
|
'eyebrow' => 'Helpdesk',
|
|
'title' => 'Create ticket',
|
|
'subtitle' =>
|
|
'Raise a new support request with priority, product/service, project, category, team and full details.',
|
|
])
|
|
|
|
<form
|
|
wire:submit.prevent="save"
|
|
x-data="{ helpdeskAttachmentsUploading: false }"
|
|
x-on:livewire-upload-start="helpdeskAttachmentsUploading = true"
|
|
x-on:livewire-upload-finish="helpdeskAttachmentsUploading = false"
|
|
x-on:livewire-upload-error="helpdeskAttachmentsUploading = false"
|
|
x-on:livewire-upload-cancel="helpdeskAttachmentsUploading = false"
|
|
x-on:submit.capture="
|
|
if (helpdeskAttachmentsUploading) {
|
|
$event.preventDefault();
|
|
return;
|
|
}
|
|
|
|
$dispatch('helpdesk-editor-sync', { model: 'body' });
|
|
"
|
|
enctype="multipart/form-data"
|
|
class="helpdesk-ticket-form space-y-6"
|
|
>
|
|
<div class="overflow-hidden rounded-2xl border border-zinc-700 bg-zinc-900 shadow-sm">
|
|
<div class="border-b border-zinc-700 bg-zinc-800/80 px-6 py-4">
|
|
<h2 class="text-lg font-semibold text-zinc-100">Ticket details</h2>
|
|
<p class="mt-1 text-sm text-zinc-400">
|
|
Mandatory fields are marked with <span class="helpdesk-required-star">*</span>.
|
|
Use the searchable lists to keep the ticket correctly routed.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="grid gap-5 p-6 lg:grid-cols-3 xl:grid-cols-6">
|
|
<div class="lg:col-span-3 xl:col-span-6">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="subject">
|
|
Subject <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<input id="subject" type="text" spellcheck="true" lang="en-GB" maxlength="180" wire:model.defer="subject"
|
|
class="mt-2 block h-14 w-full max-w-4xl rounded-xl border border-zinc-700 bg-zinc-950 px-4 text-base font-medium text-zinc-100 shadow-sm outline-none transition-colors duration-150 placeholder:text-zinc-500 focus:border-blue-500 focus:bg-zinc-950 focus:ring-2 focus:ring-blue-500/40"
|
|
data-dusk="ticket-subject" dusk="ticket-subject" autocomplete="off" />
|
|
|
|
@error('subject')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
@if ($companies->isNotEmpty())
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="company_id">
|
|
Company <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="company_id" dusk="ticket-company" data-helpdesk-select2
|
|
data-placeholder="Select option" data-wire-model="company_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
|
<option value="">Select company</option>
|
|
@foreach ($companies as $company)
|
|
<option value="{{ $company->id }}" @selected((string) $company_id === (string) $company->id)>
|
|
{{ $company->name }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('company_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
@endif
|
|
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="board_id">
|
|
Board <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="board_id" data-helpdesk-select2 data-placeholder="Select option"
|
|
data-wire-model="board_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
|
data-dusk="ticket-board" dusk="ticket-board">
|
|
<option value="">No board</option>
|
|
@foreach ($boards as $board)
|
|
<option value="{{ $board->id }}" @selected((int) $board_id === (int) $board->id)>
|
|
{{ $board->name }}{{ $board->owner ? ' · ' . $board->owner->name : '' }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('board_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="priority_id">
|
|
Priority <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="priority_id" data-helpdesk-select2 data-placeholder="Select option"
|
|
data-wire-model="priority_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
|
data-dusk="ticket-priority" dusk="ticket-priority">
|
|
<option value="">Select priority</option>
|
|
@foreach ($priorities as $priority)
|
|
<option value="{{ $priority->id }}" @selected((string) $priority_id === (string) $priority->id)>{{ $priority->name }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('priority_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="category_id">
|
|
Category <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="category_id" data-helpdesk-select2 data-placeholder="Select option"
|
|
data-wire-model="category_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
|
<option value="">Select category</option>
|
|
@foreach ($categories as $category)
|
|
<option value="{{ $category->id }}" @selected((string) $category_id === (string) $category->id)>{{ $category->name }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('category_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="project_id">
|
|
Project <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="project_id" data-helpdesk-select2 data-placeholder="Select option"
|
|
data-wire-model="project_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
|
<option value="">Select project</option>
|
|
@foreach ($projects as $project)
|
|
<option value="{{ $project->id }}" @selected((string) $project_id === (string) $project->id)>
|
|
{{ $project->title ?? $project->name }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('project_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="xl:col-span-2">
|
|
<label class="block text-sm font-semibold text-zinc-200" for="team_id">
|
|
Team <span class="helpdesk-required-star">*</span>
|
|
</label>
|
|
|
|
<div class="mt-2" wire:ignore>
|
|
<select id="team_id" data-helpdesk-select2 data-placeholder="Select option"
|
|
data-wire-model="team_id"
|
|
class="block w-full rounded-xl border-zinc-700 bg-zinc-950 text-zinc-100 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
|
<option value="">Select team</option>
|
|
@foreach ($teams as $team)
|
|
<option value="{{ $team->id }}" @selected((string) $team_id === (string) $team->id)>{{ $team->name }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
@error('team_id')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="lg:col-span-3 xl:col-span-6">
|
|
<fieldset class="rounded-2xl border border-zinc-700 bg-zinc-950/70 p-4">
|
|
<div class="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
|
<legend class="text-sm font-semibold text-zinc-200">
|
|
Tags
|
|
</legend>
|
|
|
|
<span class="text-xs text-zinc-500">
|
|
Optional · select all that apply
|
|
</span>
|
|
</div>
|
|
|
|
<div class="mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
|
@forelse ($tags as $tag)
|
|
<label for="tag_{{ $tag->id }}"
|
|
class="flex cursor-pointer items-center gap-3 rounded-xl border border-zinc-700 bg-zinc-900 px-4 py-3 text-sm font-medium text-zinc-200 transition hover:border-blue-500 hover:bg-zinc-800">
|
|
<input id="tag_{{ $tag->id }}" type="checkbox" wire:model.defer="tag_ids"
|
|
value="{{ $tag->id }}"
|
|
class="h-4 w-4 rounded border-zinc-600 bg-zinc-950 text-blue-600 focus:ring-blue-500">
|
|
|
|
<span class="truncate">
|
|
{{ $tag->name }}
|
|
</span>
|
|
</label>
|
|
@empty
|
|
<div
|
|
class="rounded-xl border border-dashed border-zinc-700 bg-zinc-900 px-4 py-3 text-sm text-zinc-400">
|
|
No tags are available.
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
|
|
@error('tag_ids')
|
|
<p class="mt-3 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
|
|
@error('tag_ids.*')
|
|
<p class="mt-3 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</fieldset>
|
|
</div>
|
|
|
|
<div class="xl:col-span-2">
|
|
<x-helpdesk::date-picker id="due_at" model="due_at" label="Due date"
|
|
placeholder="Select due date" value="{{ $due_at }}" />
|
|
|
|
@error('due_at')
|
|
<p class="mt-2 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="lg:col-span-3 xl:col-span-6">
|
|
<x-helpdesk::html-editor
|
|
label="Details"
|
|
rows="12"
|
|
placeholder="Describe the issue, expected outcome, steps to reproduce and any useful context..."
|
|
wire:model="body"
|
|
editor-dusk="ticket-body-editor"
|
|
/>
|
|
|
|
<p class="mt-2 flex items-center gap-2 text-xs font-medium text-zinc-400">
|
|
<i class="fa-solid fa-circle-info text-blue-400" aria-hidden="true"></i>
|
|
Rich formatting is available. Browser spelling suggestions appear by right-clicking or Ctrl-clicking red-underlined words.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="lg:col-span-3 xl:col-span-6">
|
|
<div class="rounded-2xl border border-zinc-700 bg-zinc-950/70 p-4"
|
|
x-data="helpdeskAttachmentDropzone('attachments')"
|
|
x-on:dragover.prevent="dragging = true"
|
|
x-on:dragleave.prevent="dragging = false"
|
|
x-on:drop.prevent="dropFiles($event)"
|
|
x-on:livewire-upload-start="uploading = true; progress = 0"
|
|
x-on:livewire-upload-progress="progress = $event.detail.progress"
|
|
x-on:livewire-upload-finish="uploading = false; progress = 100"
|
|
x-on:livewire-upload-error="uploading = false"
|
|
x-bind:class="dragging ? 'border-blue-400 bg-blue-500/10' : ''">
|
|
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
<div>
|
|
<label class="block text-sm font-semibold text-zinc-200" for="attachments">
|
|
Attachments
|
|
</label>
|
|
|
|
<p class="mt-1 text-sm text-zinc-500">
|
|
Drag and drop screenshots, PDFs, logs, source files or documents. PHP, JS, RPG/RPGLE, CLLE and other source files are accepted.
|
|
</p>
|
|
</div>
|
|
|
|
<label for="attachments"
|
|
class="inline-flex cursor-pointer items-center justify-center gap-2 rounded-xl bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-zinc-950">
|
|
<i class="fa-solid fa-paperclip" aria-hidden="true"></i>
|
|
<span>Add attachments</span>
|
|
</label>
|
|
</div>
|
|
|
|
<label for="attachments"
|
|
class="mt-4 flex cursor-pointer flex-col items-center justify-center rounded-2xl border border-dashed border-zinc-700 bg-zinc-900/70 px-4 py-8 text-center transition hover:border-blue-500 hover:bg-zinc-900"
|
|
x-bind:class="dragging ? 'border-blue-400 bg-blue-500/10' : ''">
|
|
<i class="fa-solid fa-cloud-arrow-up text-2xl text-blue-300" aria-hidden="true"></i>
|
|
<span class="mt-3 text-sm font-bold text-zinc-100">Drop files here or click to browse</span>
|
|
<span class="mt-1 text-xs text-zinc-500">Maximum {{ (int) config('helpdesk.max_upload_kb', 10240) }} KB per file.</span>
|
|
</label>
|
|
|
|
<input id="attachments" type="file" wire:model="attachments" multiple accept="{{ $helpdeskAttachmentAccept }}" class="sr-only"
|
|
x-ref="input" x-on:change="refreshSelectedFiles()">
|
|
|
|
<template x-if="selectedFiles.length > 0">
|
|
<div class="mt-4 grid gap-2 sm:grid-cols-2">
|
|
<template x-for="file in selectedFiles" :key="file.name + file.size">
|
|
<div class="flex items-center gap-3 rounded-xl border border-zinc-700 bg-zinc-900 px-3 py-2 text-xs text-zinc-300">
|
|
<i class="fa-regular fa-file-lines text-blue-300" aria-hidden="true"></i>
|
|
<span class="min-w-0 flex-1 truncate" x-text="file.name"></span>
|
|
<span class="shrink-0 text-zinc-500" x-text="formatSize(file.size)"></span>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<div x-show="uploading" x-cloak
|
|
class="mt-4 rounded-xl border border-blue-500/30 bg-blue-500/10 px-4 py-3 text-sm font-medium text-blue-200">
|
|
<div class="flex items-center justify-between gap-3">
|
|
<span class="inline-flex items-center gap-2"><i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>Uploading attachments...</span>
|
|
<span x-text="progress + '%'"></span>
|
|
</div>
|
|
<div class="mt-3 h-2 overflow-hidden rounded-full bg-zinc-800">
|
|
<div class="h-full rounded-full bg-blue-500 transition-all" x-bind:style="`width: ${progress}%`"></div>
|
|
</div>
|
|
</div>
|
|
|
|
@error('attachments')
|
|
<p class="mt-3 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
|
|
@error('attachments.*')
|
|
<p class="mt-3 text-sm text-red-500">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center justify-end gap-3 border-t border-zinc-700 bg-zinc-900 px-6 py-4">
|
|
<button type="button" wire:click="clearForm" wire:loading.attr="disabled" wire:target="clearForm"
|
|
class="inline-flex items-center gap-2 rounded-xl bg-red-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50"
|
|
data-dusk="ticket-create-clear" dusk="ticket-create-clear">
|
|
<i class="fa-solid fa-eraser" aria-hidden="true"></i>
|
|
<span wire:loading.remove wire:target="clearForm">Clear</span>
|
|
<span wire:loading wire:target="clearForm">Clearing...</span>
|
|
</button>
|
|
|
|
<a href="{{ route('helpdesk.tickets.index') }}" wire:navigate
|
|
class="rounded-xl bg-blue-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700">
|
|
Cancel
|
|
</a>
|
|
|
|
<button type="submit"
|
|
class="inline-flex items-center gap-2 rounded-xl bg-green-600 px-5 py-2 text-sm font-semibold text-white shadow-sm hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
|
data-dusk="ticket-create-submit" dusk="ticket-create-submit" wire:loading.attr="disabled" wire:target="save,attachments" x-bind:disabled="helpdeskAttachmentsUploading" wire:dirty.class="ring-2 ring-amber-400/40">
|
|
<i class="fa-regular fa-floppy-disk" aria-hidden="true"></i>
|
|
<span wire:loading.remove wire:target="save,attachments">Create Ticket</span>
|
|
<span wire:loading wire:target="attachments">Uploading...</span>
|
|
<span wire:loading wire:target="save">Creating...</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<script>
|
|
(() => {
|
|
window.helpdeskAttachmentDropzone = window.helpdeskAttachmentDropzone || function (inputId) {
|
|
return {
|
|
dragging: false,
|
|
uploading: false,
|
|
progress: 0,
|
|
selectedFiles: [],
|
|
dropFiles(event) {
|
|
this.dragging = false;
|
|
const input = this.$refs.input || document.getElementById(inputId);
|
|
|
|
if (!input || !event.dataTransfer?.files?.length) {
|
|
return;
|
|
}
|
|
|
|
input.files = event.dataTransfer.files;
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
this.refreshSelectedFiles();
|
|
},
|
|
refreshSelectedFiles() {
|
|
const input = this.$refs.input || document.getElementById(inputId);
|
|
this.selectedFiles = input?.files ? Array.from(input.files) : [];
|
|
},
|
|
formatSize(bytes) {
|
|
if (!bytes) {
|
|
return '0 B';
|
|
}
|
|
|
|
const units = ['B', 'KB', 'MB', 'GB'];
|
|
const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
|
|
return `${(bytes / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
|
|
},
|
|
};
|
|
};
|
|
|
|
const resetTicketCreateFiles = () => {
|
|
document.querySelectorAll('.helpdesk-ticket-form #attachments').forEach((input) => {
|
|
input.value = '';
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
});
|
|
};
|
|
|
|
const appendPastedFiles = (event) => {
|
|
const files = Array.from(event.detail?.files || []);
|
|
const input = document.querySelector('.helpdesk-ticket-form #attachments');
|
|
|
|
if (!input || files.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const transfer = new DataTransfer();
|
|
Array.from(input.files || []).forEach((file) => transfer.items.add(file));
|
|
files.forEach((file) => transfer.items.add(file));
|
|
input.files = transfer.files;
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
};
|
|
|
|
document.addEventListener('helpdesk-form-cleared', resetTicketCreateFiles);
|
|
document.addEventListener('helpdesk-editor-files-pasted', appendPastedFiles);
|
|
|
|
if (window.Livewire?.on) {
|
|
window.Livewire.on('helpdesk-form-cleared', resetTicketCreateFiles);
|
|
}
|
|
})();
|
|
</script>
|
|
</div> |