diff --git a/src/components/portal/portal-ticket-form.tsx b/src/components/portal/portal-ticket-form.tsx index 9c3bf1c..05bb4c2 100644 --- a/src/components/portal/portal-ticket-form.tsx +++ b/src/components/portal/portal-ticket-form.tsx @@ -12,10 +12,10 @@ import { sanitizeEditorHtml } from "@/components/ui/rich-text-editor" import { useAuth } from "@/lib/auth-client" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" -import { Textarea } from "@/components/ui/textarea" import { Button } from "@/components/ui/button" import { CategorySelectFields } from "@/components/tickets/category-select" import { Dropzone } from "@/components/ui/dropzone" +import { RichTextEditor, sanitizeEditorHtml } from "@/components/ui/rich-text-editor" const DEFAULT_PRIORITY: TicketPriority = "MEDIUM" @@ -55,7 +55,12 @@ export function PortalTicketForm() { const trimmedSubject = subject.trim() const trimmedSummary = summary.trim() - const trimmedDescription = description.trim() + const sanitizedDescription = sanitizeEditorHtml(description || "") + const plainDescription = sanitizedDescription.replace(/<[^>]*>/g, "").trim() + if (plainDescription.length === 0) { + toast.error("Descreva o que aconteceu para que possamos ajudar melhor.", { id: "portal-new-ticket" }) + return + } setIsSubmitting(true) toast.loading("Abrindo chamado...", { id: "portal-new-ticket" }) @@ -73,8 +78,9 @@ export function PortalTicketForm() { subcategoryId: subcategoryId as Id<"ticketSubcategories">, }) - if (trimmedDescription.length > 0) { - const htmlBody = sanitizeEditorHtml(toHtml(trimmedDescription)) + if (plainDescription.length > 0) { + const htmlBody = sanitizedDescription || toHtml(trimmedSummary || trimmedSubject) + const typedAttachments = attachments.map((file) => ({ storageId: file.storageId as Id<"_storage">, name: file.name, @@ -92,6 +98,7 @@ export function PortalTicketForm() { toast.success("Chamado criado com sucesso!", { id: "portal-new-ticket" }) setAttachments([]) + setAttachments([]) router.replace(`/portal/tickets/${id}`) } catch (error) { console.error(error) @@ -136,13 +143,11 @@ export function PortalTicketForm() { -