Fix portal comment submission with attachments
This commit is contained in:
parent
f606ac1570
commit
275daa7c6e
1 changed files with 8 additions and 14 deletions
|
|
@ -39,16 +39,6 @@ const priorityTone: Record<TicketWithDetails["priority"], string> = {
|
||||||
URGENT: "bg-rose-100 text-rose-700",
|
URGENT: "bg-rose-100 text-rose-700",
|
||||||
}
|
}
|
||||||
|
|
||||||
function toHtmlFromText(text: string) {
|
|
||||||
const escaped = text
|
|
||||||
.replace(/&/g, "&")
|
|
||||||
.replace(/</g, "<")
|
|
||||||
.replace(/>/g, ">")
|
|
||||||
.replace(/"/g, """)
|
|
||||||
.replace(/'/g, "'")
|
|
||||||
return `<p>${escaped.replace(/\n/g, "<br />")}</p>`
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PortalTicketDetailProps {
|
interface PortalTicketDetailProps {
|
||||||
ticketId: string
|
ticketId: string
|
||||||
}
|
}
|
||||||
|
|
@ -244,16 +234,20 @@ export function PortalTicketDetail({ ticketId }: PortalTicketDetailProps) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!convexUserId || !ticket) return
|
if (!convexUserId || !ticket) return
|
||||||
const trimmed = comment.trim()
|
const rawHtml = comment || ""
|
||||||
const hasText = trimmed.length > 0
|
const sanitizedHtml = sanitizeEditorHtml(rawHtml)
|
||||||
if (!hasText && attachments.length === 0) {
|
const plainText = typeof window !== "undefined"
|
||||||
|
? new DOMParser().parseFromString(sanitizedHtml, "text/html").body.textContent?.replace(/\u00a0/g, " ").trim() ?? ""
|
||||||
|
: sanitizedHtml.replace(/<[^>]*>/g, "").replace(/ /g, " ").trim()
|
||||||
|
const hasMeaningfulText = plainText.length > 0
|
||||||
|
if (!hasMeaningfulText && attachments.length === 0) {
|
||||||
toast.error("Adicione uma mensagem ou anexe ao menos um arquivo antes de enviar.")
|
toast.error("Adicione uma mensagem ou anexe ao menos um arquivo antes de enviar.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const toastId = "portal-add-comment"
|
const toastId = "portal-add-comment"
|
||||||
toast.loading("Enviando comentário...", { id: toastId })
|
toast.loading("Enviando comentário...", { id: toastId })
|
||||||
try {
|
try {
|
||||||
const htmlBody = hasText ? sanitizeEditorHtml(toHtmlFromText(trimmed)) : "<p></p>"
|
const htmlBody = hasMeaningfulText ? sanitizedHtml : "<p></p>"
|
||||||
await addComment({
|
await addComment({
|
||||||
ticketId: ticket.id as Id<"tickets">,
|
ticketId: ticket.id as Id<"tickets">,
|
||||||
authorId: convexUserId as Id<"users">,
|
authorId: convexUserId as Id<"users">,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue