@@ -2,54 +2,10 @@ import React from 'react';
2
2
import { Container , Form , Button , Col } from 'react-bootstrap' ;
3
3
4
4
class ExpenseForm extends React . Component {
5
- constructor ( props ) {
6
- super ( props ) ;
7
- this . state = {
8
- date : '' ,
9
- expense : '' ,
10
- location : '' ,
11
- cost : '' ,
12
- validated : false
13
- }
14
- this . handleChange = this . handleChange . bind ( this )
15
- this . handleSubmit = this . handleSubmit . bind ( this )
16
- }
17
-
18
- handleChange ( event ) {
19
- event . preventDefault ( ) ;
20
- const { name, value } = event . target
21
- this . setState ( {
22
- [ name ] : value
23
- } )
24
-
25
- }
26
-
27
- handleSubmit ( event ) {
28
- event . preventDefault ( ) ;
29
-
30
- const form = event . currentTarget ;
31
- if ( form . checkValidity ( ) === false ) {
32
- this . setState ( { validated : true } ) ;
33
- } else {
34
- const randomID = Math . floor ( Math . random ( ) * 100 ) ;
35
- this . props . handleExpenseSubmit ( randomID ,
36
- this . state . date , this . state . location ,
37
- this . state . expense , this . state . cost ) ;
38
-
39
- this . setState ( {
40
- 'date' : '' ,
41
- 'expense' : '' ,
42
- 'location' : '' ,
43
- 'cost' : '' ,
44
- 'validated' : false
45
- } ) ;
46
- }
47
- }
48
-
49
5
render ( ) {
50
6
return (
51
7
< Container className = "expense-form" >
52
- < Form noValidate validated = { this . state . validated } onSubmit = { this . handleSubmit } autoComplete = "off" >
8
+ < Form noValidate validated = { this . props . validated } onSubmit = { this . props . handleSubmit } autoComplete = "off" >
53
9
< Form . Row className = "align-items-center" >
54
10
< Form . Group >
55
11
< Col >
@@ -58,8 +14,8 @@ class ExpenseForm extends React.Component {
58
14
id = "expense-date"
59
15
type = "date"
60
16
name = "date"
61
- value = { this . state . date }
62
- onChange = { this . handleChange } />
17
+ value = { this . props . date }
18
+ onChange = { this . props . handleChange } />
63
19
< Form . Control . Feedback type = "invalid" > Please provide a date!</ Form . Control . Feedback >
64
20
</ Col >
65
21
</ Form . Group >
@@ -71,8 +27,8 @@ class ExpenseForm extends React.Component {
71
27
type = "text"
72
28
placeholder = "Location"
73
29
name = "location"
74
- value = { this . state . location }
75
- onChange = { this . handleChange } />
30
+ value = { this . props . location }
31
+ onChange = { this . props . handleChange } />
76
32
< Form . Control . Feedback type = "invalid" > Please provide a location!</ Form . Control . Feedback >
77
33
</ Col >
78
34
</ Form . Group >
@@ -86,8 +42,8 @@ class ExpenseForm extends React.Component {
86
42
type = "text"
87
43
placeholder = "Expense Description"
88
44
name = "expense"
89
- value = { this . state . expense }
90
- onChange = { this . handleChange } />
45
+ value = { this . props . expense }
46
+ onChange = { this . props . handleChange } />
91
47
< Form . Control . Feedback type = "invalid" > Please provide a description!</ Form . Control . Feedback >
92
48
</ Col >
93
49
</ Form . Group >
@@ -101,8 +57,8 @@ class ExpenseForm extends React.Component {
101
57
min = "0.01"
102
58
placeholder = "$000.00"
103
59
name = "cost"
104
- value = { this . state . cost }
105
- onChange = { this . handleChange } />
60
+ value = { this . props . cost }
61
+ onChange = { this . props . handleChange } />
106
62
< Form . Control . Feedback type = "invalid" > Please provide a cost greater than 0!</ Form . Control . Feedback >
107
63
</ Col >
108
64
</ Form . Group >
0 commit comments