@@ -2,12 +2,13 @@ import { StyleSheet, Text, View } from "react-native";
2
2
import Input from "./Input" ;
3
3
import Button from "../UI/Button" ;
4
4
import { useState } from "react" ;
5
+ import { getFormattedDate } from "../../util/date" ;
5
6
6
- function ExpenseForm ( { onCancel, onSubmit, submitButtonLabel} ) {
7
+ function ExpenseForm ( { onCancel, onSubmit, submitButtonLabel, defaultValues } ) {
7
8
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 : "" ,
11
12
} ) ;
12
13
13
14
function inputChangeHandler ( inputIdentifier , enteredValue ) {
@@ -20,7 +21,12 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
20
21
}
21
22
22
23
function submitHandler ( ) {
23
-
24
+ const expenseData = {
25
+ amount : + inputValues . amount ,
26
+ date : new Date ( inputValues . date ) ,
27
+ description : inputValues . description
28
+ }
29
+ onSubmit ( expenseData )
24
30
}
25
31
26
32
@@ -34,7 +40,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
34
40
textInputConfig = { {
35
41
keyboardType : "decimal-pad" ,
36
42
onChangeText : inputChangeHandler . bind ( this , "amount" ) ,
37
- value : inputValues [ " amount" ] ,
43
+ value : inputValues . amount ,
38
44
} }
39
45
/>
40
46
< Input
@@ -44,7 +50,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
44
50
placeholder : "YYYY-MM-DD" ,
45
51
maxLength : 10 ,
46
52
onChangeText : inputChangeHandler . bind ( this , "date" ) ,
47
- value : inputValues [ " date" ] ,
53
+ value : inputValues . date ,
48
54
} }
49
55
/>
50
56
</ View >
@@ -54,7 +60,7 @@ function ExpenseForm({onCancel, onSubmit, submitButtonLabel}) {
54
60
textInputConfig = { {
55
61
multiline : true ,
56
62
onChangeText : inputChangeHandler . bind ( this , "description" ) ,
57
- value : inputValues [ " description" ] ,
63
+ value : inputValues . description ,
58
64
} }
59
65
/>
60
66
0 commit comments