refactor: add getCategoryLabel helper
- Import CATEGORIES from types - Add getCategoryLabel function - Display category label instead of id
This commit is contained in:
parent
44f8f57d4a
commit
fa073d2c9a
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { View, Text, TouchableOpacity, StyleSheet, FlatList } from 'react-native';
|
||||
import { COLORS, FONTS } from '../constants/theme';
|
||||
import { Transaction } from '../types';
|
||||
import { Transaction, CATEGORIES } from '../types';
|
||||
import { formatRupiah, formatDate } from '../utils/helpers';
|
||||
|
||||
interface TransactionListProps {
|
||||
@ -13,6 +13,11 @@ export const TransactionList: React.FC<TransactionListProps> = ({
|
||||
transactions,
|
||||
onDelete,
|
||||
}) => {
|
||||
const getCategoryLabel = (categoryId: string) => {
|
||||
const category = CATEGORIES.find((c) => c.id === categoryId);
|
||||
return category ? category.label : categoryId;
|
||||
};
|
||||
|
||||
const renderItem = ({ item }: { item: Transaction }) => {
|
||||
const isExpense = item.type === 'expense';
|
||||
|
||||
@ -20,7 +25,7 @@ export const TransactionList: React.FC<TransactionListProps> = ({
|
||||
<View style={styles.item}>
|
||||
<View style={styles.info}>
|
||||
<Text style={styles.description}>{item.description}</Text>
|
||||
<Text style={styles.category}>{item.category}</Text>
|
||||
<Text style={styles.category}>{getCategoryLabel(item.category)}</Text>
|
||||
<Text style={styles.date}>{formatDate(item.date)}</Text>
|
||||
</View>
|
||||
<View style={styles.amountContainer}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user