diff --git a/convex/checklistTemplates.ts b/convex/checklistTemplates.ts index c9c410a..34c75cc 100644 --- a/convex/checklistTemplates.ts +++ b/convex/checklistTemplates.ts @@ -259,3 +259,23 @@ export const update = mutation({ return { ok: true } }, }) + +export const remove = mutation({ + args: { + tenantId: v.string(), + actorId: v.id("users"), + templateId: v.id("ticketChecklistTemplates"), + }, + handler: async (ctx, { tenantId, actorId, templateId }) => { + await requireAdmin(ctx, actorId, tenantId) + + const existing = await ctx.db.get(templateId) + if (!existing || existing.tenantId !== tenantId) { + throw new ConvexError("Template de checklist não encontrado.") + } + + await ctx.db.delete(templateId) + + return { ok: true } + }, +}) diff --git a/src/components/admin/devices/admin-devices-overview.tsx b/src/components/admin/devices/admin-devices-overview.tsx index cdd5d90..70e4916 100644 --- a/src/components/admin/devices/admin-devices-overview.tsx +++ b/src/components/admin/devices/admin-devices-overview.tsx @@ -4000,7 +4000,7 @@ export function DeviceDetails({ device }: DeviceDetailsProps) { + ) : null} ) diff --git a/src/components/settings/checklist-templates-manager.tsx b/src/components/settings/checklist-templates-manager.tsx index f6f5dea..7ae3c07 100644 --- a/src/components/settings/checklist-templates-manager.tsx +++ b/src/components/settings/checklist-templates-manager.tsx @@ -266,6 +266,7 @@ export function ChecklistTemplatesManager() { ) as Array<{ id: Id<"companies">; name: string }> | undefined const updateTemplate = useMutation(api.checklistTemplates.update) + const removeTemplate = useMutation(api.checklistTemplates.remove) const companyOptions = useMemo( () => (companies ?? []).map((c) => ({ id: c.id, name: c.name })).sort((a, b) => a.name.localeCompare(b.name, "pt-BR")), @@ -303,6 +304,22 @@ export function ChecklistTemplatesManager() { } } + const handleDelete = async (tpl: ChecklistTemplateRow) => { + if (!viewerId) return + const ok = confirm(`Excluir o template "${tpl.name}"? Esta ação não pode ser desfeita.`) + if (!ok) return + try { + await removeTemplate({ + tenantId, + actorId: viewerId, + templateId: tpl.id, + }) + toast.success("Template excluído.") + } catch (error) { + toast.error(error instanceof Error ? error.message : "Falha ao excluir template.") + } + } + return (
@@ -366,12 +383,22 @@ export function ChecklistTemplatesManager() { ) : null}
- - +
diff --git a/src/components/tickets/ticket-checklist-card.tsx b/src/components/tickets/ticket-checklist-card.tsx index 7cf23a4..469ac80 100644 --- a/src/components/tickets/ticket-checklist-card.tsx +++ b/src/components/tickets/ticket-checklist-card.tsx @@ -376,7 +376,7 @@ export function TicketChecklistCard({