1
- import React , { Component } from ' react' ;
2
- import { Template } from ' ../../components' ;
3
- import { connect } from ' react-redux' ;
4
- import { SERVER_IP } from ' ../../private' ;
5
- import ' ./orderForm.css' ;
1
+ import React , { Component } from " react" ;
2
+ import { Template } from " ../../components" ;
3
+ import { connect } from " react-redux" ;
4
+ import { SERVER_IP } from " ../../private" ;
5
+ import " ./orderForm.css" ;
6
6
7
- const ADD_ORDER_URL = `${ SERVER_IP } /api/add-order`
7
+ const ADD_ORDER_URL = `${ SERVER_IP } /api/add-order` ;
8
8
9
9
const mapStateToProps = ( state ) => ( {
10
- auth : state . auth ,
11
- } )
10
+ auth : state . auth ,
11
+ } ) ;
12
12
13
13
class OrderForm extends Component {
14
- constructor ( props ) {
15
- super ( props ) ;
16
- this . state = {
17
- order_item : "" ,
18
- quantity : "1"
19
- }
20
- }
14
+ constructor ( props ) {
15
+ super ( props ) ;
16
+ this . state = {
17
+ order_item : "" ,
18
+ quantity : "1" ,
19
+ } ;
20
+ }
21
21
22
- menuItemChosen ( event ) {
23
- this . setState ( { item : event . target . value } ) ;
24
- }
22
+ menuItemChosen ( event ) {
23
+ this . setState ( { order_item : event . target . value } ) ;
24
+ }
25
25
26
- menuQuantityChosen ( event ) {
27
- this . setState ( { quantity : event . target . value } ) ;
28
- }
26
+ menuQuantityChosen ( event ) {
27
+ this . setState ( { quantity : event . target . value } ) ;
28
+ }
29
29
30
- submitOrder ( event ) {
31
- event . preventDefault ( ) ;
32
- if ( this . state . order_item === "" ) return ;
33
- fetch ( ADD_ORDER_URL , {
34
- method : ' POST' ,
35
- body : JSON . stringify ( {
36
- order_item : this . state . order_item ,
37
- quantity : this . state . quantity ,
38
- ordered_by : this . props . auth . email || ' Unknown!' ,
39
- } ) ,
40
- headers : {
41
- ' Content-Type' : ' application/json'
42
- }
43
- } )
44
- . then ( res => res . json ( ) )
45
- . then ( response => console . log ( "Success" , JSON . stringify ( response ) ) )
46
- . catch ( error => console . error ( error ) ) ;
47
- }
30
+ submitOrder ( event ) {
31
+ event . preventDefault ( ) ;
32
+ if ( this . state . order_item === "" ) return ;
33
+ fetch ( ADD_ORDER_URL , {
34
+ method : " POST" ,
35
+ body : JSON . stringify ( {
36
+ order_item : this . state . order_item ,
37
+ quantity : this . state . quantity ,
38
+ ordered_by : this . props . auth . email || " Unknown!" ,
39
+ } ) ,
40
+ headers : {
41
+ " Content-Type" : " application/json" ,
42
+ } ,
43
+ } )
44
+ . then ( ( res ) => res . json ( ) )
45
+ . then ( ( response ) => console . log ( "Success" , JSON . stringify ( response ) ) )
46
+ . catch ( ( error ) => console . error ( error ) ) ;
47
+ }
48
48
49
- render ( ) {
50
- return (
51
- < Template >
52
- < div className = "form-wrapper" >
53
- < form >
54
- < label className = "form-label" > I'd like to order...</ label > < br />
55
- < select
56
- value = { this . state . order_item }
57
- onChange = { ( event ) => this . menuItemChosen ( event ) }
58
- className = "menu-select"
59
- >
60
- < option value = "" defaultValue disabled hidden > Lunch menu</ option >
61
- < option value = "Soup of the Day" > Soup of the Day</ option >
62
- < option value = "Linguini With White Wine Sauce" > Linguini With White Wine Sauce</ option >
63
- < option value = "Eggplant and Mushroom Panini" > Eggplant and Mushroom Panini</ option >
64
- < option value = "Chili Con Carne" > Chili Con Carne</ option >
65
- </ select > < br />
66
- < label className = "qty-label" > Qty:</ label >
67
- < select value = { this . state . quantity } onChange = { ( event ) => this . menuQuantityChosen ( event ) } >
68
- < option value = "1" > 1</ option >
69
- < option value = "2" > 2</ option >
70
- < option value = "3" > 3</ option >
71
- < option value = "4" > 4</ option >
72
- < option value = "5" > 5</ option >
73
- < option value = "6" > 6</ option >
74
- </ select >
75
- < button type = "button" className = "order-btn" onClick = { ( event ) => this . submitOrder ( event ) } > Order It!</ button >
76
- </ form >
77
- </ div >
78
- </ Template >
79
- ) ;
80
- }
49
+ render ( ) {
50
+ return (
51
+ < Template >
52
+ < div className = "form-wrapper" >
53
+ < form >
54
+ < label className = "form-label" > I'd like to order...</ label >
55
+ < br />
56
+ < select
57
+ value = { this . state . order_item }
58
+ onChange = { ( event ) => this . menuItemChosen ( event ) }
59
+ className = "menu-select"
60
+ >
61
+ < option value = "" defaultValue disabled hidden >
62
+ Lunch menu
63
+ </ option >
64
+ < option value = "Soup of the Day" > Soup of the Day</ option >
65
+ < option value = "Linguini With White Wine Sauce" >
66
+ Linguini With White Wine Sauce
67
+ </ option >
68
+ < option value = "Eggplant and Mushroom Panini" >
69
+ Eggplant and Mushroom Panini
70
+ </ option >
71
+ < option value = "Chili Con Carne" > Chili Con Carne</ option >
72
+ </ select >
73
+ < br />
74
+ < label className = "qty-label" > Qty:</ label >
75
+ < select
76
+ value = { this . state . quantity }
77
+ onChange = { ( event ) => this . menuQuantityChosen ( event ) }
78
+ >
79
+ < option value = "1" > 1</ option >
80
+ < option value = "2" > 2</ option >
81
+ < option value = "3" > 3</ option >
82
+ < option value = "4" > 4</ option >
83
+ < option value = "5" > 5</ option >
84
+ < option value = "6" > 6</ option >
85
+ </ select >
86
+ < button
87
+ type = "button"
88
+ className = "order-btn"
89
+ onClick = { ( event ) => this . submitOrder ( event ) }
90
+ >
91
+ Order It!
92
+ </ button >
93
+ </ form >
94
+ </ div >
95
+ </ Template >
96
+ ) ;
97
+ }
81
98
}
82
99
83
- export default connect ( mapStateToProps , null ) ( OrderForm ) ;
100
+ export default connect ( mapStateToProps , null ) ( OrderForm ) ;
0 commit comments