Skip to content

Commit 78f9fb7

Browse files
committed
fixed undefined function when fetching expenses
1 parent 6e9d9a0 commit 78f9fb7

File tree

6 files changed

+1246
-37
lines changed

6 files changed

+1246
-37
lines changed

components/ManageExpense/ExpenseForm.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { StyleSheet, Text, View } from "react-native";
22
import Input from "./Input";
33
import Button from "../UI/Button";
44
import { useState } from "react";
5+
import { getFormattedDate } from "../../util/date";
56

6-
function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
7+
function ExpenseForm({onCancel, onSubmit, submitButtonLabel, defaultValues}) {
78
const [inputValues, setInputValues] = useState({
8-
amount: "",
9-
date: "",
10-
description: "",
9+
amount: defaultValues ? defaultValues.amount.toString() : "",
10+
date: defaultValues ? getFormattedDate(defaultValues.date) : "",
11+
description: defaultValues ? defaultValues.description : "",
1112
});
1213

1314
function inputChangeHandler(inputIdentifier, enteredValue) {
@@ -20,7 +21,12 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
2021
}
2122

2223
function submitHandler() {
23-
24+
const expenseData = {
25+
amount: +inputValues.amount,
26+
date: new Date(inputValues.date),
27+
description: inputValues.description
28+
}
29+
onSubmit(expenseData)
2430
}
2531

2632

@@ -34,7 +40,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
3440
textInputConfig={{
3541
keyboardType: "decimal-pad",
3642
onChangeText: inputChangeHandler.bind(this, "amount"),
37-
value: inputValues["amount"],
43+
value: inputValues.amount,
3844
}}
3945
/>
4046
<Input
@@ -44,7 +50,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
4450
placeholder: "YYYY-MM-DD",
4551
maxLength: 10,
4652
onChangeText: inputChangeHandler.bind(this, "date"),
47-
value: inputValues["date"],
53+
value: inputValues.date,
4854
}}
4955
/>
5056
</View>
@@ -54,7 +60,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
5460
textInputConfig={{
5561
multiline: true,
5662
onChangeText: inputChangeHandler.bind(this, "description"),
57-
value: inputValues["description"],
63+
value: inputValues.description,
5864
}}
5965
/>
6066

0 commit comments

Comments
 (0)