ServerDataTransfer.js
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { Component } from 'react';
import { connect } from 'react-redux';
import * as SelectActionCreators from './actions/profilationSelect'
import LemaApi from '../service/service.js'
class ServerDataTransfer extends Component {
constructor(props) {
super(props)
this.state = {
change: false
}
// necessario per legare il this al componente nel metodo onClick
this.onClick = this.onClick.bind(this);
}
onClick() {
let request = {
Job: this.props.steps[0].job,
Service: this.props.steps[0].service,
Expend: this.props.steps[1].expend,
Period: this.props.steps[1].period,
Light: this.props.steps[1].light,
Gas: this.props.steps[1].gas,
Environment: this.props.steps[2].environment,
Flexibility: this.props.steps[3].flexibility,
Customizable: this.props.steps[4].customizable
// add more properties...
};
const lemaApi = new LemaApi();
lemaApi.saveProfilationData(request);
this.setState(this.state = {change: !this.change})
}
render() {
console.info("********* STATE IN COMPONENT *********");
console.info(this.props.steps);
{/** this works! **/}
return (
<div>
<ul>
<li><b>JOB:</b> {this.props.steps[0].job} </li>
<li><b>SERVICE:</b> {this.props.steps[0].service} </li>
</ul>
<div>
<input type="button" value="Invia Dati" onClick={this.onClick} />
</div>
</div>
)
}
}
const mapStateToProps = state => {
return {
activationSteps: state.ProfilationSelectReducer.activationSteps,
steps: state.ProfilationSelectReducer.steps
}
};
const mapDispatchToProps = dispatch => ({
updatePropValue: (steps, activeStep) => dispatch(SelectActionCreators.changeValue(steps, activeStep)),
updateActivation: (index, prop, value) => dispatch(SelectActionCreators.updateActivation(index, prop, value))
});
export default connect(mapStateToProps, mapDispatchToProps)(ServerDataTransfer);