feat: add form validation
- Add Alert for validation errors - Check amount and description - Validate positive number
This commit is contained in:
parent
fa073d2c9a
commit
fafc765b3f
@ -6,6 +6,7 @@ import {
|
||||
TouchableOpacity,
|
||||
StyleSheet,
|
||||
ScrollView,
|
||||
Alert,
|
||||
} from 'react-native';
|
||||
import { COLORS, FONTS } from '../constants/theme';
|
||||
import { Transaction, CATEGORIES } from '../types';
|
||||
@ -22,11 +23,20 @@ export const TransactionForm: React.FC<TransactionFormProps> = ({ onAdd }) => {
|
||||
const [category, setCategory] = useState('lainnya');
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!amount || !description) return;
|
||||
if (!amount || !description) {
|
||||
Alert.alert('Error', 'Mohon isi jumlah dan deskripsi');
|
||||
return;
|
||||
}
|
||||
|
||||
const numAmount = parseInt(amount, 10);
|
||||
if (isNaN(numAmount) || numAmount <= 0) {
|
||||
Alert.alert('Error', 'Jumlah harus angka positif');
|
||||
return;
|
||||
}
|
||||
|
||||
const transaction: Transaction = {
|
||||
id: generateId(),
|
||||
amount: parseInt(amount, 10),
|
||||
amount: numAmount,
|
||||
description,
|
||||
type,
|
||||
category,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user