Crear Asunto funciona
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { api } from '$lib/utils/api';
|
||||
import { toast } from '$lib/stores/toast';
|
||||
import { api } from '$lib/utils/api';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
export let ticketId: string;
|
||||
export let users: any[] = [];
|
||||
@@ -43,20 +43,18 @@
|
||||
|
||||
isSubmitting = true;
|
||||
try {
|
||||
// Si hay archivo usamos FormData, si no JSON normal
|
||||
// 1. Crear el issue con JSON
|
||||
const newIssue = await api.post(`/tickets/${ticketId}/issues`, {
|
||||
content: content.trim(),
|
||||
priority,
|
||||
tagged_user_ids: taggedUserIds
|
||||
});
|
||||
|
||||
// 2. Si hay archivo, subirlo en request separado
|
||||
if (file) {
|
||||
const formData = new FormData();
|
||||
formData.append('content', content.trim());
|
||||
formData.append('priority', priority);
|
||||
taggedUserIds.forEach(id => formData.append('tagged_user_ids', id));
|
||||
formData.append('file', file);
|
||||
await api.postForm(`/tickets/${ticketId}/issues`, formData);
|
||||
} else {
|
||||
await api.post(`/tickets/${ticketId}/issues`, {
|
||||
content: content.trim(),
|
||||
priority,
|
||||
tagged_user_ids: taggedUserIds
|
||||
});
|
||||
await api.postForm(`/tickets/${ticketId}/issues/${newIssue.id}/attachment`, formData);
|
||||
}
|
||||
|
||||
toast.success('Asunto creado correctamente');
|
||||
@@ -83,7 +81,7 @@
|
||||
on:click={handleClose}
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
on:keydown={(e) => e.key === 'Escape' && handleClose()}
|
||||
on:keydown={e => e.key === 'Escape' && handleClose()}
|
||||
/>
|
||||
|
||||
<!-- Modal -->
|
||||
@@ -91,21 +89,21 @@
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between px-6 py-4 border-b border-gray-200">
|
||||
<h3 class="text-lg font-semibold text-gray-900">Crear Asunto</h3>
|
||||
<button
|
||||
type="button"
|
||||
on:click={handleClose}
|
||||
class="text-gray-400 hover:text-gray-500"
|
||||
>
|
||||
<button type="button" on:click={handleClose} class="text-gray-400 hover:text-gray-500">
|
||||
<span class="sr-only">Cerrar</span>
|
||||
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Body -->
|
||||
<div class="px-6 py-5 space-y-5">
|
||||
|
||||
<!-- Contenido -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">
|
||||
@@ -141,10 +139,10 @@
|
||||
<!-- Usuarios a etiquetar -->
|
||||
{#if users.length > 0}
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Etiquetar usuarios
|
||||
</label>
|
||||
<div class="max-h-40 overflow-y-auto border border-gray-200 rounded-md divide-y divide-gray-100">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2"> Etiquetar usuarios </label>
|
||||
<div
|
||||
class="max-h-40 overflow-y-auto border border-gray-200 rounded-md divide-y divide-gray-100"
|
||||
>
|
||||
{#each users as user}
|
||||
<label class="flex items-center gap-3 px-3 py-2 hover:bg-gray-50 cursor-pointer">
|
||||
<input
|
||||
@@ -157,7 +155,8 @@
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="text-sm font-medium text-gray-900">
|
||||
{user.first_name} {user.last_name}
|
||||
{user.first_name}
|
||||
{user.last_name}
|
||||
</span>
|
||||
<span class="text-xs text-gray-500">{user.email}</span>
|
||||
</div>
|
||||
@@ -166,7 +165,10 @@
|
||||
</div>
|
||||
{#if taggedUserIds.length > 0}
|
||||
<p class="text-xs text-blue-600 mt-1">
|
||||
{taggedUserIds.length} usuario{taggedUserIds.length > 1 ? 's' : ''} seleccionado{taggedUserIds.length > 1 ? 's' : ''}
|
||||
{taggedUserIds.length} usuario{taggedUserIds.length > 1 ? 's' : ''} seleccionado{taggedUserIds.length >
|
||||
1
|
||||
? 's'
|
||||
: ''}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -174,9 +176,7 @@
|
||||
|
||||
<!-- Adjunto -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Adjunto (opcional)
|
||||
</label>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1"> Adjunto (opcional) </label>
|
||||
<input
|
||||
bind:this={fileInput}
|
||||
type="file"
|
||||
@@ -227,4 +227,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -73,9 +73,11 @@
|
||||
|
||||
isSubmittingComment = true;
|
||||
try {
|
||||
const comment = await api.post(`/tickets/${ticketId}/comments`, {
|
||||
content: newComment.trim(),
|
||||
is_internal: false
|
||||
const comment = await api.post(`/tickets/${ticketId}/issues`, {
|
||||
content: content.trim(),
|
||||
priority,
|
||||
tagged_user_ids: taggedUserIds
|
||||
|
||||
});
|
||||
comments = [...comments, comment];
|
||||
newComment = '';
|
||||
|
||||
Reference in New Issue
Block a user