import { router } from 'expo-router'; import { StatusBar } from 'expo-status-bar'; import { useState } from 'react'; import { KeyboardAvoidingView, Platform, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { getDB } from '../db'; export default function AddTransactionScreen() { const insets = useSafeAreaInsets(); const [amount, setAmount] = useState(''); const [category, setCategory] = useState(''); const [description, setDescription] = useState(''); const [type, setType] = useState<'income' | 'expense'>('expense'); const [date, setDate] = useState(new Date().toISOString().split('T')[0]); // YYYY-MM-DD const handleSave = async () => { if (!amount || !category) { alert('Please fill in amount and category'); return; } try { const db = getDB(); await db.runAsync( 'INSERT INTO transactions (amount, category, date, description, type) VALUES (?, ?, ?, ?, ?)', [parseFloat(amount), category, date, description, type] ); router.back(); } catch (error) { console.error(error); alert('Failed to save transaction'); } }; return ( {/* Header */} New Transaction {/* Type Selector */} setType('expense')} > Expense setType('income')} > Income {/* Amount Input */} Amount {/* Details Form */} Category {['Food', 'Transport', 'Shopping', 'Entertainment', 'Bills', 'Health', 'Salary', 'Investment', 'Other'].map((cat) => ( setCategory(cat)} className={`px-4 py-2 rounded-full border ${category === cat ? 'bg-blue-600 border-blue-600' : 'bg-gray-50 border-gray-200 dark:bg-gray-700 dark:border-gray-600'}`} > {cat} ))} Date Description (Optional) {/* Save Button */} Save Transaction ); }