Reverte opcionalidade de subcategoria no portal

This commit is contained in:
Esdras Renan 2025-10-13 18:08:34 -03:00
parent 6a04ef4843
commit 9f85cbaba5
3 changed files with 7 additions and 31 deletions

View file

@ -1,6 +1,6 @@
"use client"
import { useCallback, useMemo, useState } from "react"
import { useMemo, useState } from "react"
import { useRouter } from "next/navigation"
import { useMutation } from "convex/react"
import { toast } from "sonner"
@ -45,20 +45,9 @@ export function PortalTicketForm() {
const [subcategoryId, setSubcategoryId] = useState<string | null>(null)
const [attachments, setAttachments] = useState<Array<{ storageId: string; name: string; size?: number; type?: string }>>([])
const [isSubmitting, setIsSubmitting] = useState(false)
const [hasSubcategoryOptions, setHasSubcategoryOptions] = useState(false)
const isFormValid = useMemo(() => {
return Boolean(
subject.trim() &&
description.trim() &&
categoryId &&
(hasSubcategoryOptions ? subcategoryId : true)
)
}, [subject, description, categoryId, subcategoryId, hasSubcategoryOptions])
const handleSecondaryOptionsChange = useCallback((hasOptions: boolean) => {
setHasSubcategoryOptions((prev) => (prev === hasOptions ? prev : hasOptions))
}, [])
return Boolean(subject.trim() && description.trim() && categoryId && subcategoryId)
}, [subject, description, categoryId, subcategoryId])
async function handleSubmit(event: React.FormEvent) {
event.preventDefault()
@ -86,7 +75,7 @@ export function PortalTicketForm() {
queueId: undefined,
requesterId: viewerId,
categoryId: categoryId as Id<"ticketCategories">,
subcategoryId: subcategoryId ? (subcategoryId as Id<"ticketSubcategories">) : undefined,
subcategoryId: subcategoryId as Id<"ticketSubcategories">,
})
if (plainDescription.length > 0) {
@ -169,10 +158,9 @@ export function PortalTicketForm() {
subcategoryId={subcategoryId}
onCategoryChange={setCategoryId}
onSubcategoryChange={setSubcategoryId}
onSecondaryOptionsChange={handleSecondaryOptionsChange}
layout="stacked"
categoryLabel="Categoria *"
subcategoryLabel={hasSubcategoryOptions ? "Subcategoria *" : "Subcategoria (opcional)"}
subcategoryLabel="Subcategoria *"
secondaryEmptyLabel="Selecione uma categoria"
/>
<div className="space-y-1">