diff --git a/frontend/src/app/(app)/settings/email/page.tsx b/frontend/src/app/(app)/settings/email/page.tsx index 0b5bed3..0f9e1c1 100644 --- a/frontend/src/app/(app)/settings/email/page.tsx +++ b/frontend/src/app/(app)/settings/email/page.tsx @@ -6,6 +6,7 @@ import { updateEmailTemplate, getEmailLog, sendTestEmail, + syncInboundEmail, type EmailTemplate, type EmailLogEntry, } from "@/lib/api"; @@ -42,6 +43,8 @@ export default function EmailPage() { const [testTo, setTestTo] = useState(""); const [testResult, setTestResult] = useState<{ ok: boolean; text: string } | null>(null); const [testing, setTesting] = useState(false); + const [syncing, setSyncing] = useState(false); + const [syncResult, setSyncResult] = useState<{ ok: boolean; text: string } | null>(null); const fetchData = useCallback(async () => { setLoading(true); @@ -118,6 +121,24 @@ export default function EmailPage() { } }; + const handleSync = async () => { + setSyncing(true); + setSyncResult(null); + try { + const r = await syncInboundEmail(); + setSyncResult({ + ok: r.success, + text: r.success + ? `Revisados: ${r.checkedCount}, agregados al ticket: ${r.inserted}, omitidos: ${r.skipped}${r.error ? ` (${r.error})` : ""}` + : r.error || "Error en la sincronización", + }); + } catch (err) { + setSyncResult({ ok: false, text: err instanceof Error ? err.message : "Error en la sincronización" }); + } finally { + setSyncing(false); + } + }; + if (!authLoading && user?.role !== "admin") { return (
@@ -243,6 +264,37 @@ export default function EmailPage() {
+
+
+
+ + Respuestas por correo +
+ {syncResult && ( +
+ {syncResult.text} +
+ )} +
+ +
+ + Lee la casilla Gmail y agrega como comentarios las respuestas con + etiqueta [HelpDesk HD-000123]. El worker lo hace solo cada 5 minutos. + Requiere scope gmail.readonly autorizado en admin.google.com. + +
+
+
Últimos envíos diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index b1d34e1..2e8425a 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -383,3 +383,13 @@ export async function sendTestEmail(to: string) { body: JSON.stringify({ to }), }); } + +export async function syncInboundEmail() { + return fetchApi<{ + success: boolean; + checkedCount: number; + inserted: number; + skipped: number; + error?: string; + }>("/api/helpdesk/email/inbound/sync", { method: "POST" }); +}