// Recharts from CDN const { PieChart, Pie, Cell, ResponsiveContainer } = Recharts; const categories = ["Food", "Housing", "Gym", "Business", "Entertainment", "Other"]; const colors = { green: "#5FAF7A", beige: "#E6E2D9", teal: "#6FA7A3", dark: "#3F5F5F", yellow: "#E5C46A", orange: "#E36A3D" }; function App() { const [transactions, setTransactions] = React.useState([]); const [accounts, setAccounts] = React.useState([]); const [budgets, setBudgets] = React.useState({}); const [goals, setGoals] = React.useState([]); const [form, setForm] = React.useState({ name: "", amount: "", type: "expense", category: "Food", accountName: "", accountBalance: "" }); React.useEffect(() => { const data = JSON.parse(localStorage.getItem("financeApp")); if (data) { setTransactions(data.transactions || []); setAccounts(data.accounts || []); setBudgets(data.budgets || {}); setGoals(data.goals || []); } }, []); React.useEffect(() => { localStorage.setItem("financeApp", JSON.stringify({ transactions, accounts, budgets, goals })); }, [transactions, accounts, budgets, goals]); const addTransaction = () => { if (!form.name || !form.amount) return; setTransactions([...transactions, { ...form, amount: parseFloat(form.amount) }]); setForm({ ...form, name: "", amount: "" }); }; const totalIncome = transactions.filter(t => t.type === "income").reduce((a, t) => a + t.amount, 0); const totalExpenses = transactions.filter(t => t.type === "expense").reduce((a, t) => a + t.amount, 0); const savings = totalIncome - totalExpenses; const netWorth = accounts.reduce((a, acc) => a + acc.balance, 0); const totalBudget = Object.values(budgets).reduce((a, b) => a + (b || 0), 0); const spendingStatus = totalExpenses > totalBudget ? "High" : "On Track"; const pieData = [ { name: "Income", value: totalIncome }, { name: "Spending", value: totalExpenses }, { name: "Savings", value: savings > 0 ? savings : 0 } ]; const pieColors = [colors.teal, colors.orange, colors.yellow]; return (

Finance Dashboard

{/* Summary */}

Monthly Summary

Income: ${totalIncome.toFixed(2)}

Spending: ${totalExpenses.toFixed(2)}

Savings: ${savings.toFixed(2)}

Breakdown

{pieData.map((entry, index) => ( ))}
{/* Accounts */}

Accounts

setForm({ ...form, accountName: e.target.value })} /> setForm({ ...form, accountBalance: e.target.value })} /> {accounts.map((a, i) => (
{a.name} - ${a.balance}
))}

Total: ${netWorth.toFixed(2)}

{/* Budget */}

Budget

{categories.map(cat => (
{cat} setBudgets({ ...budgets, [cat]: parseFloat(e.target.value) || 0 })} />
))}

Total Budget: ${totalBudget.toFixed(2)}

{/* Transactions */}

Transactions

setForm({ ...form, name: e.target.value })} /> setForm({ ...form, amount: e.target.value })} /> {transactions.map((t, i) => (
{t.name} {t.type === "expense" ? "-" : "+"}${t.amount}
))}
); } const root = ReactDOM.createRoot(document.getElementById("root")); root.render();