refactor: use CATEGORIES from types
- Import CATEGORIES from types/index - Map category.label for display - Use category.id for state
This commit is contained in:
parent
e328b656af
commit
44f8f57d4a
@ -8,18 +8,13 @@ import {
|
|||||||
ScrollView,
|
ScrollView,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { COLORS, FONTS } from '../constants/theme';
|
import { COLORS, FONTS } from '../constants/theme';
|
||||||
import { Transaction } from '../types';
|
import { Transaction, CATEGORIES } from '../types';
|
||||||
import { generateId, getCurrentDate } from '../utils/helpers';
|
import { generateId, getCurrentDate } from '../utils/helpers';
|
||||||
|
|
||||||
interface TransactionFormProps {
|
interface TransactionFormProps {
|
||||||
onAdd: (transaction: Transaction) => void;
|
onAdd: (transaction: Transaction) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CATEGORIES = [
|
|
||||||
'makanan', 'transport', 'belanja', 'hiburan', 'kesehatan',
|
|
||||||
'pendidikan', 'investasi', 'gaji', 'lainnya'
|
|
||||||
];
|
|
||||||
|
|
||||||
export const TransactionForm: React.FC<TransactionFormProps> = ({ onAdd }) => {
|
export const TransactionForm: React.FC<TransactionFormProps> = ({ onAdd }) => {
|
||||||
const [amount, setAmount] = useState('');
|
const [amount, setAmount] = useState('');
|
||||||
const [description, setDescription] = useState('');
|
const [description, setDescription] = useState('');
|
||||||
@ -104,20 +99,20 @@ export const TransactionForm: React.FC<TransactionFormProps> = ({ onAdd }) => {
|
|||||||
<View style={styles.categoryContainer}>
|
<View style={styles.categoryContainer}>
|
||||||
{CATEGORIES.map((cat) => (
|
{CATEGORIES.map((cat) => (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
key={cat}
|
key={cat.id}
|
||||||
style={[
|
style={[
|
||||||
styles.categoryButton,
|
styles.categoryButton,
|
||||||
category === cat && styles.categoryButtonActive,
|
category === cat.id && styles.categoryButtonActive,
|
||||||
]}
|
]}
|
||||||
onPress={() => setCategory(cat)}
|
onPress={() => setCategory(cat.id)}
|
||||||
>
|
>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.categoryText,
|
styles.categoryText,
|
||||||
category === cat && styles.categoryTextActive,
|
category === cat.id && styles.categoryTextActive,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{cat}
|
{cat.label}
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user