ProfilationStep1.js
6.78 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React, { Component } from 'react';
import Select from "react-select";
import { Creatable } from "react-select";
import * as SelectActionCreators from '../../actions/profilationSelect'
import { connect } from 'react-redux';
var serviceOptions = [
{ value: "light", label: "Elettricità" },
{ value: "gas", label: "Gas" },
{ value: "both", label: "Elettricità e Gas" }
];
var jobOptions = [
{ value: "edilizia", label: "Edilizia" },
{ value: "editoria", label: "Editoria" },
{ value: "educazione", label: "Educazione" }
];
function onInputKeyDown(event) {
switch (event.keyCode) {
case 9: // TAB
// Extend default TAB behavior by doing something here
break;
case 13: // ENTER
// Override default ENTER behavior by doing stuff here and then preventing default
break;
}
}
class ProfilationStep1 extends Component{
constructor(props){
super(props)
this.changeField=this.changeField.bind(this)
}
changeField(mobile,name, event, props) {
if(mobile){
event=event.target
}
console.log('select',name,event,props)
var completed = true;
if (event !== null && event.value !== "") {
for (var property in props.step) {
if (props.step.hasOwnProperty(property)) {
if (
property !== name &&
property !== "isComplete" &&
property !== "isActive"
) {
completed = completed && props.step[property] !== "";
}
}
}
} else {
completed = false;
}
let step = {...props.step};
step[name] = event.value;
if(name==='service' && event.value==='light'){
props.updateActivation(1,'gasVal','NotSelected')
props.updateActivation(1,'gasBill','NoFile')
props.updateActivation(3,'checkAcciseRidotte',{...this.props.activationSteps[3].checkAcciseRidotte,
required:false})
}
if(name==='service' && event.value==='gas'){
props.updateActivation(1,'lightVal','NotSelected')
props.updateActivation(1,'lightBill','NoFile')
props.updateActivation(3,'checkAcciseRidotte',{...this.props.activationSteps[3].checkAcciseRidotte,
required:true})
}
if(name==='service' && event.value==='both'){
props.updateActivation(1,'lightVal','')
props.updateActivation(1,'gasVal','')
props.updateActivation(3,'checkAcciseRidotte',{...this.props.activationSteps[3].checkAcciseRidotte,
required:true})
}
step.isComplete = completed;
props.updatePropValue(props.index, step);
if(name==='job'){
this.serviceInput.focus();
}
}
render(){
return(
<div className="ProfilationStep ProfilationStep--one" onClick={e => this.props.activeStep(this.props.index)}>
<p className="ProfilationStep__bold">
Costruisci in pochi secondi la tua tariffa flat, 100% online.
</p>
<div className="d-flex">
<span> La mia attività si occupa di
<Creatable
openOnClick={false}
autosize={true}
creatable={true}
name="job"
placeholder="placeholder"
value={this.props.step.job}
onChange={e => this.changeField(false,"job", e, this.props)}
options={jobOptions}
onFocus={e => this.props.activeStep(this.props.index)}
promptTextCreator={(label) => ` ${label} `}
className = "select-full-height select-z-index"
onInputKeyDown={onInputKeyDown}
/>
{window.innerWidth>=768&&<br/>}ed ho bisogno di
{window.innerWidth>=0 && <Select
ref={(input) => { this.serviceInput = input; }}
searchable={false}
autosize={true}
name="service"
placeholder="placeholder"
value={this.props.step.service}
onChange={e => this.changeField(false,"service", e, this.props)}
options={serviceOptions}
onFocus={e => this.props.activeStep(this.props.index)}
className = "select-z-index"
openOnFocus={true}
/>}</span>
{/*window.innerWidth<768 &&
<select
ref={(input) => { this.serviceInput = input; }}
name="service"
onChange={e => this.changeField(true,"service", e, this.props)}
value={this.props.step.service}
onFocus={e => this.props.activeStep(this.props.index)}
className='mobileSelect'
>
<option value='' disabled></option>
<option value='light'>Elettricità</option>
<option value='gas'>Gas</option>
<option value='both'>Elettricità e Gas</option>
</select>
*/}
</div>
<p tabindex="0" className="ProfilationStep__underline" onClick={() => this.props.showModal('FURNITURE_MODAL')}>
Per il tuo business hai più sedi e forniture?
</p>
</div>
)
}
}
/*const ProfilationStep1 = props => (
);*/
/*ProfilationStep1.propTypes = {
//isComplete: PropTypes.bool.isRequired,
//isActive: PropTypes.bool.isRequired
step: PropTypes.object.isRequired,
index: PropTypes.number.isRequired,
updatePropValue: PropTypes.func.isRequired
};
export default ProfilationStep1;*/
const mapStateToProps = state => {
return {
activationSteps:state.ProfilationSelectReducer.activationSteps,
//solutions:state.ProfilationSelectReducer.solutions,
modalOpen:state.ProfilationSelectReducer.saveModalOpen
}};
const mapDispatchToProps = dispatch => ({
/*updatePropValue: (prop,value,index,complete) =>
dispatch(SelectActionCreators.changeValue(prop,value,index,complete)),
updateStoreValue: (prop,value) =>
dispatch(SelectActionCreators.changeProp(prop,value)),*/
updateActivation: (index,prop,value) => dispatch(SelectActionCreators.updateActivation(index,prop,value)),
showModal: (modalName) =>
dispatch(SelectActionCreators.showModal(modalName)),
});
export default connect(mapStateToProps, mapDispatchToProps)(ProfilationStep1);