import React, { useState, useEffect } from 'react'; import TemplateList from './components/TemplateList'; import TemplateEditor from './components/TemplateEditor'; import { ViewState, EmailTemplate, SQL_SCHEMA } from './types'; import { getTemplates, deleteTemplate, generateUUID } from './services/storage'; import { Database } from 'lucide-react'; const App: React.FC = () => { const [view, setView] = useState('dashboard'); const [templates, setTemplates] = useState([]); const [selectedTemplate, setSelectedTemplate] = useState(undefined); const [showSchema, setShowSchema] = useState(false); const [isLoading, setIsLoading] = useState(false); useEffect(() => { refreshTemplates(); }, []); const refreshTemplates = async () => { setIsLoading(true); try { const data = await getTemplates(); setTemplates(data); } catch (err) { console.error("Refresh Error:", err); } finally { setIsLoading(false); } }; const handleCreate = () => { setSelectedTemplate(undefined); setView('editor'); }; const handleEdit = (t: EmailTemplate) => { setSelectedTemplate(t); setView('editor'); }; const handleClone = (t: EmailTemplate) => { const clonedTemplate: EmailTemplate = { ...t, id: generateUUID(), name: `${t.name} (Copia)`, updatedAt: new Date().toISOString() }; setSelectedTemplate(clonedTemplate); setView('editor'); }; const handleDelete = async (id: string) => { if (window.confirm("Sei sicuro di voler eliminare questo template?")) { await deleteTemplate(id); await refreshTemplates(); } }; const handleSave = async () => { await refreshTemplates(); setView('dashboard'); }; return (
{view === 'dashboard' && ( <> {isLoading ? (
Caricamento...
) : ( )}
)} {view === 'editor' && ( setView('dashboard')} onSave={handleSave} /> )} {showSchema && (

Configurazione DB

{SQL_SCHEMA}
)}
); }; export default App;