fix: criação de template de checklist

- Permite isArchived na mutation checklistTemplates.create\n- Troca Select por SearchableCombobox no campo Empresa
This commit is contained in:
esdrasrenan 2025-12-13 21:14:51 -03:00
parent 8a045c0131
commit 51c9cab79c
2 changed files with 23 additions and 16 deletions

View file

@ -167,8 +167,9 @@ export const create = mutation({
required: v.optional(v.boolean()),
}),
),
isArchived: v.optional(v.boolean()),
},
handler: async (ctx, { tenantId, actorId, name, description, companyId, items }) => {
handler: async (ctx, { tenantId, actorId, name, description, companyId, items, isArchived }) => {
await requireAdmin(ctx, actorId, tenantId)
const normalizedName = normalizeTemplateName(name)
@ -185,6 +186,7 @@ export const create = mutation({
const normalizedItems = normalizeTemplateItems(items, {})
const normalizedDescription = normalizeTemplateDescription(description)
const archivedFlag = typeof isArchived === "boolean" ? isArchived : false
const now = Date.now()
return ctx.db.insert("ticketChecklistTemplates", {
@ -193,7 +195,7 @@ export const create = mutation({
description: normalizedDescription ?? undefined,
companyId: companyId ?? undefined,
items: normalizedItems,
isArchived: false,
isArchived: archivedFlag,
createdAt: now,
updatedAt: now,
createdBy: actorId,

View file

@ -16,7 +16,7 @@ import { Checkbox } from "@/components/ui/checkbox"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { SearchableCombobox, type SearchableComboboxOption } from "@/components/ui/searchable-combobox"
import { Switch } from "@/components/ui/switch"
import { Textarea } from "@/components/ui/textarea"
@ -76,6 +76,15 @@ function TemplateEditorDialog({
const [items, setItems] = useState<DraftItem[]>([{ id: crypto.randomUUID(), text: "", required: true }])
const [archived, setArchived] = useState<boolean>(false)
const companyComboboxOptions = useMemo<SearchableComboboxOption[]>(() => {
const sortedCompanies = [...companies].sort((a, b) => a.name.localeCompare(b.name, "pt-BR"))
return [
{ value: NO_COMPANY_VALUE, label: "Global (todas)" },
...sortedCompanies.map((company) => ({ value: String(company.id), label: company.name })),
]
}, [companies])
useEffect(() => {
if (!open) return
setName(template?.name ?? "")
@ -148,19 +157,15 @@ function TemplateEditorDialog({
</div>
<div className="space-y-2">
<Label>Empresa</Label>
<Select value={companyValue} onValueChange={setCompanyValue}>
<SelectTrigger>
<SelectValue placeholder="Global" />
</SelectTrigger>
<SelectContent className="rounded-xl">
<SelectItem value={NO_COMPANY_VALUE}>Global (todas)</SelectItem>
{companies.map((company) => (
<SelectItem key={company.id} value={String(company.id)}>
{company.name}
</SelectItem>
))}
</SelectContent>
</Select>
<SearchableCombobox
value={companyValue}
onValueChange={(nextValue) => setCompanyValue(nextValue ?? NO_COMPANY_VALUE)}
options={companyComboboxOptions}
placeholder="Selecionar empresa"
searchPlaceholder="Buscar empresa..."
triggerClassName="h-9 rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-neutral-800 shadow-sm"
contentClassName="rounded-xl"
/>
</div>
</div>