import { useState, useEffect } from 'react'; import { api, session } from '@/lib/api'; import { Plus, Trash2, TestTube2, Globe, CheckCircle } from 'lucide-react'; interface Instance { instance_name: string; url: string; database: string; username: string; type: string; } export default function Connections() { const [instances, setInstances] = useState([]); const [showForm, setShowForm] = useState(false); const [loading, setLoading] = useState(false); const [form, setForm] = useState({ instance_name: 'default', url: '', database: '', username: '', credential: '', is_api_key: true, }); function load() { const key = session.getKey(); if (!key) return; api.listCredentials(key).then((r) => setInstances(r.instances)).catch(console.error); } useEffect(load, []); async function handleAdd(e: React.FormEvent) { e.preventDefault(); const key = session.getKey(); if (!key) return; setLoading(true); try { await api.addCredential(key, form); setShowForm(false); setForm({ instance_name: 'default', url: '', database: '', username: '', credential: '', is_api_key: true }); load(); } catch (err) { alert(err instanceof Error ? err.message : 'Failed to add connection'); } finally { setLoading(false); } } async function handleDelete(name: string) { if (!confirm(`Remove "${name}"?`)) return; const key = session.getKey(); if (!key) return; await api.deleteCredential(key, name); load(); } return (

Odoo Connections

Manage your Odoo ERP instances.

{/* Existing connections */} {instances.length === 0 && !showForm && (

No connections yet

Add your Odoo instance to get started.

)} {instances.map((inst) => (

{inst.instance_name}

{inst.url}

Database

{inst.database}

Username

{inst.username}

Auth Type

{inst.type}

))} {/* Add connection form panel */} {showForm && (

Add Odoo Connection

setForm({ ...form, instance_name: v })} placeholder="e.g. production" /> setForm({ ...form, url: v })} placeholder="https://mycompany.odoo.com" />
setForm({ ...form, database: v })} placeholder="mydb" /> setForm({ ...form, username: v })} placeholder="admin@company.com" />
setForm({ ...form, credential: v })} placeholder={form.is_api_key ? 'Paste your Odoo API key' : 'Odoo password'} type="password" />
)}
); } function Field({ label, value, onChange, placeholder, type = 'text' }: { label: string; value: string; onChange: (v: string) => void; placeholder?: string; type?: string; }) { return (
onChange(e.target.value)} placeholder={placeholder} required className="w-full border border-gray-200 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent" />
); }