From 469608a10b60c2679e2ed2df03a64209847ef2c1 Mon Sep 17 00:00:00 2001 From: esdrasrenan Date: Sat, 13 Dec 2025 11:59:34 -0300 Subject: [PATCH] =?UTF-8?q?ui:=20ajustar=20tabelas=20de=20automa=C3=A7?= =?UTF-8?q?=C3=B5es=20e=20sidebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/app-sidebar.tsx | 6 +- .../automations/automation-runs-dialog.tsx | 43 +++-- .../automations/automations-manager.tsx | 154 ++++++++++-------- 3 files changed, 117 insertions(+), 86 deletions(-) diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 2159727..a63f3a7 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -83,10 +83,9 @@ const navigation: NavigationGroup[] = [ children: [ { title: "Todos os tickets", url: "/tickets", icon: ClipboardList, requiredRole: "staff" }, { title: "Resolvidos", url: "/tickets/resolved", icon: ShieldCheck, requiredRole: "staff" }, + { title: "Modo Play", url: "/play", icon: PlayCircle, requiredRole: "staff" }, ], }, - { title: "Automações", url: "/automations", icon: Waypoints, requiredRole: "agent" }, - { title: "Modo Play", url: "/play", icon: PlayCircle, requiredRole: "staff" }, { title: "Agenda", url: "/agenda", icon: CalendarDays, requiredRole: "staff" }, { title: "Dispositivos", url: "/admin/devices", icon: MonitorCog, requiredRole: "admin" }, { title: "Empréstimos", url: "/emprestimos", icon: Package, requiredRole: "staff" }, @@ -108,7 +107,7 @@ const navigation: NavigationGroup[] = [ }, { title: "Administração", - requiredRole: "admin", + requiredRole: "agent", items: [ { title: "Cadastros", @@ -124,6 +123,7 @@ const navigation: NavigationGroup[] = [ { title: "Templates de relatórios", url: "/admin/report-templates", icon: LayoutTemplate, requiredRole: "admin" }, ], }, + { title: "Automações", url: "/automations", icon: Waypoints, requiredRole: "agent" }, { title: "Orquestração", url: "/admin/channels", diff --git a/src/components/automations/automation-runs-dialog.tsx b/src/components/automations/automation-runs-dialog.tsx index 8c0ac7b..6c8abb9 100644 --- a/src/components/automations/automation-runs-dialog.tsx +++ b/src/components/automations/automation-runs-dialog.tsx @@ -37,7 +37,11 @@ const EVENT_LABELS: Record = { } function formatDateTime(timestamp: number) { - return new Date(timestamp).toLocaleString("pt-BR") + const date = new Date(timestamp) + return { + date: date.toLocaleDateString("pt-BR"), + time: date.toLocaleTimeString("pt-BR", { hour: "2-digit", minute: "2-digit", second: "2-digit" }), + } } function statusBadge(status: AutomationRunRow["status"]) { @@ -85,7 +89,7 @@ export function AutomationRunsDialog({ const rows = (results ?? []) as unknown as AutomationRunRow[] return ( - +
@@ -116,15 +120,15 @@ export function AutomationRunsDialog({
-
- +
+
- - - - - - + + + + + + @@ -171,6 +175,9 @@ export function AutomationRunsDialog({ const badge = statusBadge(run.status) const eventLabel = EVENT_LABELS[run.eventType] ?? run.eventType const actionsCount = run.actionsApplied?.length ?? 0 + const actionsLabel = + actionsCount === 1 ? "Aplicou 1 ação" : `Aplicou ${actionsCount} ações` + const createdAtLabel = formatDateTime(run.createdAt) const details = run.status === "ERROR" ? run.error ?? "Erro desconhecido" @@ -179,12 +186,17 @@ export function AutomationRunsDialog({ ? "Ignorada" : "Condições não atendidas" : actionsCount > 0 - ? `Aplicou ${actionsCount} ação(ões)` + ? actionsLabel : "Sem alterações" return ( - {formatDateTime(run.createdAt)} + +
+
{createdAtLabel.date}
+
{createdAtLabel.time}
+
+
{run.ticket ? (
@@ -197,7 +209,11 @@ export function AutomationRunsDialog({ "—" )} - {eventLabel} + + + {eventLabel} + + {badge.label} @@ -238,4 +254,3 @@ export function AutomationRunsDialog({ ) } - diff --git a/src/components/automations/automations-manager.tsx b/src/components/automations/automations-manager.tsx index 67958dc..ce355d0 100644 --- a/src/components/automations/automations-manager.tsx +++ b/src/components/automations/automations-manager.tsx @@ -51,8 +51,12 @@ function triggerLabel(trigger: string) { } function formatLastRun(timestamp: number | null) { - if (!timestamp) return "—" - return new Date(timestamp).toLocaleString("pt-BR") + if (!timestamp) return null + const date = new Date(timestamp) + return { + date: date.toLocaleDateString("pt-BR"), + time: date.toLocaleTimeString("pt-BR", { hour: "2-digit", minute: "2-digit", second: "2-digit" }), + } } function formatConditionsSummary(conditions: unknown | null) { @@ -229,17 +233,17 @@ export function AutomationsManager() { Nenhuma automação cadastrada.

) : ( -
-
+
+
- - - - - - - - + + + + + + + + @@ -270,64 +274,76 @@ export function AutomationsManager() { - {filtered.map((row) => ( - - - {row.name} - - -
- - {triggerLabel(row.trigger)} - - {row.timing === "DELAYED" && row.delayMs ? ( - - +{Math.round(row.delayMs / 60000)}m + {filtered.map((row) => { + const lastRun = formatLastRun(row.lastRunAt) + return ( + + + {row.name} + + +
+ + {triggerLabel(row.trigger)} - ) : null} -
-
- - {formatConditionsSummary(row.conditions)} - - {row.actions?.length ?? 0} - {row.runCount ?? 0} - {formatLastRun(row.lastRunAt)} - -
- handleToggle(row, checked)} - className="data-[state=checked]:bg-black data-[state=unchecked]:bg-slate-300" - /> - {row.enabled ? "Ativa" : "Inativa"} -
-
- - - - - - - handleOpenRuns(row)} className="gap-2"> - - Histórico - - handleEdit(row)} className="gap-2"> - - Editar - - handleDelete(row)} className="gap-2"> - - Excluir - - - - -
- ))} + {row.timing === "DELAYED" && row.delayMs ? ( + + +{Math.round(row.delayMs / 60000)}m + + ) : null} +
+
+ + {formatConditionsSummary(row.conditions)} + + {row.actions?.length ?? 0} + {row.runCount ?? 0} + + {lastRun ? ( +
+
{lastRun.date}
+
{lastRun.time}
+
+ ) : ( + "—" + )} +
+ +
+ handleToggle(row, checked)} + className="data-[state=checked]:bg-black data-[state=unchecked]:bg-slate-300" + /> + {row.enabled ? "Ativa" : "Inativa"} +
+
+ + + + + + + handleOpenRuns(row)} className="gap-2"> + + Histórico + + handleEdit(row)} className="gap-2"> + + Editar + + handleDelete(row)} className="gap-2"> + + Excluir + + + + +
+ ) + })}