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:
parent
8a045c0131
commit
51c9cab79c
2 changed files with 23 additions and 16 deletions
|
|
@ -167,8 +167,9 @@ export const create = mutation({
|
||||||
required: v.optional(v.boolean()),
|
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)
|
await requireAdmin(ctx, actorId, tenantId)
|
||||||
|
|
||||||
const normalizedName = normalizeTemplateName(name)
|
const normalizedName = normalizeTemplateName(name)
|
||||||
|
|
@ -185,6 +186,7 @@ export const create = mutation({
|
||||||
|
|
||||||
const normalizedItems = normalizeTemplateItems(items, {})
|
const normalizedItems = normalizeTemplateItems(items, {})
|
||||||
const normalizedDescription = normalizeTemplateDescription(description)
|
const normalizedDescription = normalizeTemplateDescription(description)
|
||||||
|
const archivedFlag = typeof isArchived === "boolean" ? isArchived : false
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
|
||||||
return ctx.db.insert("ticketChecklistTemplates", {
|
return ctx.db.insert("ticketChecklistTemplates", {
|
||||||
|
|
@ -193,7 +195,7 @@ export const create = mutation({
|
||||||
description: normalizedDescription ?? undefined,
|
description: normalizedDescription ?? undefined,
|
||||||
companyId: companyId ?? undefined,
|
companyId: companyId ?? undefined,
|
||||||
items: normalizedItems,
|
items: normalizedItems,
|
||||||
isArchived: false,
|
isArchived: archivedFlag,
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
createdBy: actorId,
|
createdBy: actorId,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import { Checkbox } from "@/components/ui/checkbox"
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Label } from "@/components/ui/label"
|
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 { Switch } from "@/components/ui/switch"
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
|
||||||
|
|
@ -76,6 +76,15 @@ function TemplateEditorDialog({
|
||||||
const [items, setItems] = useState<DraftItem[]>([{ id: crypto.randomUUID(), text: "", required: true }])
|
const [items, setItems] = useState<DraftItem[]>([{ id: crypto.randomUUID(), text: "", required: true }])
|
||||||
const [archived, setArchived] = useState<boolean>(false)
|
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(() => {
|
useEffect(() => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
setName(template?.name ?? "")
|
setName(template?.name ?? "")
|
||||||
|
|
@ -148,19 +157,15 @@ function TemplateEditorDialog({
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Empresa</Label>
|
<Label>Empresa</Label>
|
||||||
<Select value={companyValue} onValueChange={setCompanyValue}>
|
<SearchableCombobox
|
||||||
<SelectTrigger>
|
value={companyValue}
|
||||||
<SelectValue placeholder="Global" />
|
onValueChange={(nextValue) => setCompanyValue(nextValue ?? NO_COMPANY_VALUE)}
|
||||||
</SelectTrigger>
|
options={companyComboboxOptions}
|
||||||
<SelectContent className="rounded-xl">
|
placeholder="Selecionar empresa"
|
||||||
<SelectItem value={NO_COMPANY_VALUE}>Global (todas)</SelectItem>
|
searchPlaceholder="Buscar empresa..."
|
||||||
{companies.map((company) => (
|
triggerClassName="h-9 rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-neutral-800 shadow-sm"
|
||||||
<SelectItem key={company.id} value={String(company.id)}>
|
contentClassName="rounded-xl"
|
||||||
{company.name}
|
/>
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue