// ============================================================================ // public/screens/whatsapp.jsx — WhatsApp Business (Phase 6C) // ============================================================================ function WhatsAppScreen() { const [tab, setTab] = React.useState("templates"); // templates | conversations | broadcasts return (
{tab === "templates" && } {tab === "conversations" && } {tab === "broadcasts" && }
); } // ── Templates ─────────────────────────────────────────────────────────── function WaTemplatesTab() { const [tpls, setTpls] = React.useState(null); const [showCreate, setShow] = React.useState(false); const load = async () => { const r = await VoaisAPI.get("/api/whatsapp/templates"); if (r.ok) setTpls(r.data.templates); }; React.useEffect(() => { load(); }, []); const del = async (id) => { if (!confirm("Delete template?")) return; await VoaisAPI.del("/api/whatsapp/templates/" + id); load(); }; if (tpls === null) return ; return (
{tpls.length} templates
} onClick={() => setShow(true)}>New template
{tpls.map(t => (
{t.name} {t.status}
{t.category} · {t.language} · {t.code}
{t.body?.slice(0, 200)}{t.body?.length > 200 ? "..." : ""}
Sent {t.sent_count || 0}x del(t.id)}>
))}
{tpls.length === 0 && } action={ setShow(true)}>Create template}/>} {showCreate && setShow(false)} onCreated={() => { setShow(false); load(); }}/>}
); } function CreateTemplateModal({ onClose, onCreated }) { const [f, setF] = React.useState({ name: "", category: "utility", language: "en_IN", body: "", footer: "" }); const [sub, setSub] = React.useState(false); const submit = async () => { if (!f.name.trim() || !f.body.trim()) return; setSub(true); const r = await VoaisAPI.post("/api/whatsapp/templates", f); setSub(false); if (r.ok) onCreated(); else alert(r.data?.msg); }; return (
setF({...f, name: e.target.value})} placeholder="e.g. test_drive_confirmation"/>