From c801d8d820b0f596ba685dbfe111e092fc3a6c23 Mon Sep 17 00:00:00 2001 From: VPS 4 Deploy Agent Date: Sun, 28 Jun 2026 05:12:03 +0200 Subject: [PATCH] =?UTF-8?q?feat(settings):=20painel=20mostra=20API=20est?= =?UTF-8?q?=C3=A1vel=20+=20InfinityAPI=20(n=C3=A3o=20remove=20a=20infinite?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajuste: o painel de configurações lista as DUAS engines selecionáveis — "API estável" (baileys7) e "InfinityAPI" (infinite) — além da versão. Apenas a 'official' (Baileys 6, que dá 401) fica de fora da UI. Co-Authored-By: Claude Opus 4.8 --- .../frontend/components/SettingsPanel.tsx | 124 +++++++++++------- 1 file changed, 76 insertions(+), 48 deletions(-) diff --git a/newwhats.clube67.com/newwhats.local/frontend/components/SettingsPanel.tsx b/newwhats.clube67.com/newwhats.local/frontend/components/SettingsPanel.tsx index f0dfa6f..bc9d101 100644 --- a/newwhats.clube67.com/newwhats.local/frontend/components/SettingsPanel.tsx +++ b/newwhats.clube67.com/newwhats.local/frontend/components/SettingsPanel.tsx @@ -1,17 +1,35 @@ import React, { useEffect, useState, useCallback } from 'react'; -import { ShieldCheck, Check, Loader2, Tag } from 'lucide-react'; +import { ShieldCheck, LayoutGrid, Check, Loader2, Tag } from 'lucide-react'; interface SettingsPanelProps { instanceId: string | null; } -// "API estável" aponta para a engine Baileys 7 oficial (a que conecta de fato). -const STABLE_ENGINE = 'baileys7'; +// Engines oferecidas no painel. A 'official' (Baileys 6, que dá 401) fica de fora. +// baileys7 → Baileys 7 oficial (a que conecta) → rótulo "API estável" +// infinite → InfinityAPI (com botões) +const ENGINES: { + value: string; titulo: string; desc: string; icon: any; + iconCls: string; activeBorder: string; activeBg: string; checkCls: string; btnCls: string; +}[] = [ + { + value: 'baileys7', titulo: 'API estável', desc: 'Conexão recomendada do WhatsApp', + icon: ShieldCheck, iconCls: 'text-emerald-500', + activeBorder: 'border-emerald-400', activeBg: 'bg-emerald-50', checkCls: 'text-emerald-600', + btnCls: 'bg-emerald-500 hover:bg-emerald-600', + }, + { + value: 'infinite', titulo: 'InfinityAPI', desc: 'Com botões interativos (experimental)', + icon: LayoutGrid, iconCls: 'text-amber-500', + activeBorder: 'border-amber-400', activeBg: 'bg-amber-50', checkCls: 'text-amber-600', + btnCls: 'bg-amber-500 hover:bg-amber-600', + }, +]; export default function SettingsPanel({ instanceId }: SettingsPanelProps) { const [engine, setEngine] = useState(null); const [loading, setLoading] = useState(false); - const [saving, setSaving] = useState(false); + const [saving, setSaving] = useState(null); const [error, setError] = useState(null); const [version, setVersion] = useState(null); @@ -43,71 +61,81 @@ export default function SettingsPanel({ instanceId }: SettingsPanelProps) { .finally(() => setLoading(false)); }, [instanceId]); - const ativarEstavel = useCallback(async () => { - if (!instanceId || saving) return; - setSaving(true); + const selectEngine = useCallback(async (value: string) => { + if (!instanceId || saving || value === engine) return; + setSaving(value); setError(null); try { const res = await fetch(`${API_URL}/api/instances/${instanceId}/engine`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', ...authHeader() }, - body: JSON.stringify({ engine: STABLE_ENGINE }), + body: JSON.stringify({ engine: value }), }); if (res.status === 429) { const d = await res.json().catch(() => ({})); throw new Error(d.error ?? 'Aguarde o intervalo entre trocas.'); } - if (!res.ok) throw new Error('Falha ao ativar a API estável.'); - setEngine(STABLE_ENGINE); + if (!res.ok) throw new Error('Falha ao trocar a API.'); + setEngine(value); } catch (e: any) { - setError(e?.message ?? 'Erro ao ativar.'); + setError(e?.message ?? 'Erro ao trocar a API.'); } finally { - setSaving(false); + setSaving(null); } - }, [instanceId, saving]); - - const ativa = engine === STABLE_ENGINE; + }, [instanceId, saving, engine]); return (
-

Configurações

+

Configurações

+

Escolha a API de conexão do WhatsApp para esta instância.

- {/* ── API estável ─────────────────────────────────────────── */} -
-
-
- -
-
-

API estável

-

Conexão recomendada do WhatsApp

-
- {ativa && ( - - Ativa - - )} -
+ {!instanceId && ( +

Selecione uma instância primeiro.

+ )} - {!instanceId ? ( -

Selecione uma instância primeiro.

- ) : ativa ? ( -

A API estável está ativa nesta instância.

- ) : ( - - )} - {loading &&

Carregando configuração…

} - {error &&

{error}

} + {/* ── Engines ─────────────────────────────────────────────── */} +
+ {ENGINES.map((opt) => { + const Icon = opt.icon; + const ativa = engine === opt.value; + const salvando = saving === opt.value; + return ( +
+
+
+ +
+
+

{opt.titulo}

+

{opt.desc}

+
+ {ativa ? ( + + Ativa + + ) : ( + + )} +
+
+ ); + })}
+ {loading &&

Carregando configuração atual…

} + {error &&

{error}

} + {/* ── Versão ──────────────────────────────────────────────── */}