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 } 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); const data = await getTemplates(); setTemplates(data); setIsLoading(false); }; const handleCreate = () => { setSelectedTemplate(undefined); setView('editor'); }; const handleEdit = (t: EmailTemplate) => { setSelectedTemplate(t); setView('editor'); }; const handleClone = (t: EmailTemplate) => { // Create a copy of the template with a new ID and updated name const clonedTemplate: EmailTemplate = { ...t, id: crypto.randomUUID(), // Generate new ID so it's treated as a new insert name: `${t.name} (Copy)`, updatedAt: new Date().toISOString() }; setSelectedTemplate(clonedTemplate); setView('editor'); }; const handleDelete = async (id: string) => { if (window.confirm("Are you sure you want to delete this template?")) { await deleteTemplate(id); await refreshTemplates(); } }; const handleSave = async () => { await refreshTemplates(); setView('dashboard'); }; return (
{view === 'dashboard' && ( <> {isLoading ? (
Loading templates...
) : ( )}
)} {view === 'editor' && ( setView('dashboard')} onSave={handleSave} /> )} {/* Database Schema Modal (Global Help) */} {showSchema && (

Database Setup for n8n

To make this app work with your internal software, create this table in your MySQL or PostgreSQL database.

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