diff --git a/Modules/Helpdesk/Livewire/TicketCreate.php b/Modules/Helpdesk/Livewire/TicketCreate.php index 77a4d677..b2ddd5b3 100644 --- a/Modules/Helpdesk/Livewire/TicketCreate.php +++ b/Modules/Helpdesk/Livewire/TicketCreate.php @@ -86,10 +86,54 @@ final class TicketCreate extends Component $this->applyDefaults(); } + public function save(TicketService $tickets) + { + logger()->info('SAVE START'); + + try { + + logger()->info('VALIDATING'); + + $this->validate(); + + logger()->info('VALIDATED'); + + logger()->info([ + 'attachments' => count($this->attachments), + 'body' => $this->body, + ]); + + $ticket = $tickets->create(Auth::user(), [ + 'company_id' => $this->company_id, + 'subject' => $this->subject, + 'body' => $this->body, + 'board_id' => $this->board_id, + 'priority_id' => $this->priority_id, + 'category_id' => $this->category_id, + 'project_id' => $this->project_id, + 'product_id' => $this->product_id, + 'team_id' => $this->team_id, + 'due_at' => $this->due_at, + 'tag_ids' => $this->tag_ids, + ], $this->attachments); + session()->flash('success', 'Ticket ' . $ticket->reference . ' has been created.'); + + logger()->info('CREATED '.$ticket->id); + + return redirect()->route('helpdesk.tickets.index'); + + } catch (\Throwable $e) { + + logger()->error($e); + + throw $e; + } + } + /** * Store a new helpdesk ticket. */ - public function save(TicketService $tickets) + public function save_old(TicketService $tickets) { if ($this->isSaving) { return null; diff --git a/Modules/Helpdesk/Resources/views/components/html-editor.blade.php b/Modules/Helpdesk/Resources/views/components/html-editor.blade.php index 8a16c3a1..d4f42200 100644 --- a/Modules/Helpdesk/Resources/views/components/html-editor.blade.php +++ b/Modules/Helpdesk/Resources/views/components/html-editor.blade.php @@ -10,7 +10,7 @@ class="space-y-2" x-data="{ model: @js($model), - value: @entangle($model).defer, + value: @entangle($model), init() { this.$nextTick(() => { this.writeEditorValue(this.value || ''); @@ -21,33 +21,43 @@ return; } - this.$refs.editor.textContent = value || ''; + const nextValue = value || ''; + const currentValue = this.$refs.editor.innerText || ''; + + if (document.activeElement === this.$refs.editor && currentValue !== '' && currentValue !== nextValue) { + return; + } + + this.$refs.editor.textContent = nextValue; }, - syncToLivewire(live = false) { + syncToLivewire(live = true) { const value = this.$refs.editor?.innerText || ''; this.value = value; - this.$refs.input.value = value; - this.$refs.input.dispatchEvent(new Event('input', { bubbles: true })); - this.$wire.set(this.model, this.value, live); + + if (this.$refs.input) { + this.$refs.input.value = value; + } + + this.$wire.set(this.model, value, live); }, resetEditor() { this.value = ''; this.writeEditorValue(''); - this.syncToLivewire(false); + this.syncToLivewire(true); }, runCommand(command) { this.$refs.editor?.focus(); document.execCommand(command, false, null); - this.syncToLivewire(false); + this.syncToLivewire(true); }, wrapBlock(tagName) { this.$refs.editor?.focus(); document.execCommand('formatBlock', false, tagName); - this.syncToLivewire(false); + this.syncToLivewire(true); }, }" - x-on:helpdesk-editor-sync.window="if (! $event.detail?.model || $event.detail.model === @js($model)) syncToLivewire(false)" + x-on:helpdesk-editor-sync.window="if (! $event.detail?.model || $event.detail.model === @js($model)) syncToLivewire($event.detail?.live ?? true)" x-on:helpdesk-editor-reset.window="if (! $event.detail?.model || $event.detail.model === @js($model)) resetEditor()" >