11import React from 'react' ;
2+ import 'whatwg-fetch' ;
23import '../../styles/Form.css' ;
34
45class Form extends React . Component {
@@ -8,12 +9,37 @@ class Form extends React.Component {
89 title : '' ,
910 type : '' ,
1011 details : '' ,
12+ detailsPH : '' ,
1113 disabled : false
1214 } ;
1315
1416 handleChange = ( evt ) => {
15- //update state with changed input value
16- this . setState ( { [ evt . target . name ] : evt . target . value } ) ;
17+ //change details placeholder when type is selected
18+ if ( evt . target . name === 'type' ) {
19+ let placeholder = '' ;
20+ switch ( evt . target . value ) {
21+ case 'bug' :
22+ placeholder = "Please provide as many details as possible, including your device and browser, if possible" ;
23+ break ;
24+ case 'enhancement' :
25+ placeholder = "Describe how your feature might work here" ;
26+ break ;
27+ case 'question' :
28+ placeholder = "What's up?"
29+ break ;
30+ default :
31+ placeholder = "" ;
32+ break ;
33+ }
34+ //update changed input value and details placeholder text
35+ this . setState ( {
36+ [ evt . target . name ] : evt . target . value ,
37+ detailsPH : placeholder
38+ } ) ;
39+ } else {
40+ //update state with changed input value
41+ this . setState ( { [ evt . target . name ] : evt . target . value } ) ;
42+ }
1743 }
1844
1945 handleSubmit = ( evt ) => {
@@ -27,13 +53,14 @@ class Form extends React.Component {
2753 headers : {
2854 'Content-Type' : 'application/json' ,
2955 } ,
30- body : JSON . stringify ( this . state )
56+ credentials : "same-origin" ,
57+ body : this . getFormData ( )
3158 } ;
3259 //define variables needed for user feedback
3360 let status = null ;
3461 const errText = "An error has occurred submitting your feedback. Please verify your internet connection and try again later.\n\nError Code: " ;
3562 //make api fetch call to server
36- fetch ( 'https ://lp-timer.herokuapp.com /add' , requestOptions )
63+ fetch ( 'http ://192.168.0.6:5000 /add' , requestOptions )
3764 //save http status, return response text
3865 . then ( res => {
3966 status = res . status ;
@@ -58,25 +85,34 @@ class Form extends React.Component {
5885 evt . preventDefault ( ) ;
5986 }
6087
88+ getFormData = ( ) => {
89+ let data = { ...this . state } ;
90+ delete data . disabled ;
91+ data [ 'version' ] = "1.2.2" ;
92+ return JSON . stringify ( data ) ;
93+ }
94+
6195 render ( ) {
6296 return (
6397 < form onSubmit = { this . handleSubmit } >
64- < label > Your Name:</ label >
98+ < span className = "required" > required field</ span >
99+ < label className = "required" > Your Name:</ label >
65100 < input type = "text" name = "name" onChange = { this . handleChange } value = { this . state . name } disabled = { this . state . disabled } required />
66- < label > Your Email:</ label >
101+ < label className = "required" > Your Email:</ label >
67102 < input type = "email" name = "email" placeholder = "[email protected] " onChange = { this . handleChange } value = { this . state . email } disabled = { this . state . disabled } required /> 68- < label > Title of Feedback:</ label >
103+ < label className = "required" > Title of Feedback:</ label >
69104 < input type = "text" name = "title" className = "extend" placeholder = "Ex: Verbals not working" onChange = { this . handleChange } value = { this . state . title } disabled = { this . state . disabled } required />
70- < label > Type of Feedback:</ label >
105+ < label className = "required" > Type of Feedback:</ label >
71106 < select name = "type" onChange = { this . handleChange } value = { this . state . type } disabled = { this . state . disabled } required >
72107 < option value = "" > Choose one...</ option >
73108 < option value = "bug" > Bug (something isn't working)</ option >
74109 < option value = "enhancement" > Enhancement (new feature or request)</ option >
75110 < option value = "question" > Question (further information is requested) </ option >
76111 </ select >
77112 < label > Feedback Details:</ label >
78- < textarea name = "details" className = "extend" placeholder = "(optional, but encouraged)" onChange = { this . handleChange } value = { this . state . details } disabled = { this . state . disabled } />
113+ < textarea name = "details" className = "extend" placeholder = { this . state . detailsPH } onChange = { this . handleChange } value = { this . state . details } disabled = { this . state . disabled } />
79114 < input type = "submit" disabled = { this . state . disabled } />
115+
80116 </ form >
81117 )
82118 }
0 commit comments