diff --git a/components/TransactionList.tsx b/components/TransactionList.tsx new file mode 100644 index 0000000..7f0b99b --- /dev/null +++ b/components/TransactionList.tsx @@ -0,0 +1,144 @@ +import React from 'react'; +import { View, Text, TouchableOpacity, StyleSheet, FlatList } from 'react-native'; +import { COLORS, FONTS } from '../constants/theme'; +import { Transaction } from '../types'; +import { formatRupiah, formatDate } from '../utils/helpers'; + +interface TransactionListProps { + transactions: Transaction[]; + onDelete: (id: string) => void; +} + +export const TransactionList: React.FC = ({ + transactions, + onDelete, +}) => { + const renderItem = ({ item }: { item: Transaction }) => { + const isExpense = item.type === 'expense'; + + return ( + + + {item.description} + {item.category} + {formatDate(item.date)} + + + + {isExpense ? '-' : '+'}{formatRupiah(item.amount)} + + onDelete(item.id)} + > + Hapus + + + + ); + }; + + if (transactions.length === 0) { + return ( + + Belum ada transaksi + + Tambahkan transaksi pertama Anda + + + ); + } + + return ( + + Riwayat Transaksi + item.id} + renderItem={renderItem} + scrollEnabled={false} + /> + + ); +}; + +const styles = StyleSheet.create({ + container: { + margin: 16, + marginTop: 0, + }, + title: { + fontSize: FONTS.regular, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 12, + }, + item: { + backgroundColor: COLORS.card, + padding: 16, + borderRadius: 12, + marginBottom: 8, + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.05, + shadowRadius: 2, + elevation: 1, + }, + info: { + flex: 1, + }, + description: { + fontSize: FONTS.regular, + fontWeight: '600', + color: COLORS.text, + }, + category: { + fontSize: FONTS.small, + color: COLORS.textSecondary, + marginTop: 2, + }, + date: { + fontSize: FONTS.small, + color: COLORS.textSecondary, + marginTop: 2, + }, + amountContainer: { + alignItems: 'flex-end', + }, + amount: { + fontSize: FONTS.regular, + fontWeight: 'bold', + }, + income: { + color: COLORS.income, + }, + expense: { + color: COLORS.expense, + }, + deleteButton: { + marginTop: 4, + paddingHorizontal: 8, + paddingVertical: 4, + }, + deleteText: { + fontSize: FONTS.small, + color: COLORS.expense, + }, + empty: { + margin: 16, + padding: 40, + alignItems: 'center', + }, + emptyText: { + fontSize: FONTS.regular, + color: COLORS.textSecondary, + }, + emptySubtext: { + fontSize: FONTS.small, + color: COLORS.textSecondary, + marginTop: 8, + }, +}); \ No newline at end of file