TrainerModal.js
7.4 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import React, { Component } from 'react'
import ReactModal from 'react-modal';
import greenCheck from '../../img/outlineGreenCheck.svg'
import alertError from '../../img/alert_error.svg'
import * as SelectActionCreators from '../actions/profilationSelect'
import { connect } from 'react-redux';
import trainerIcon from './img/trainer-icons.svg'
import ModalValidatingInput from './ModalValidatingInput'
/*
<div className="Modal Modal-mask modal_repower Modal--save isOpen">
<div className="Modal-wrapper">
<div className="Modal-container" >
*/
class TrainerModal extends Component {
constructor(props) {
super(props);
this.state = {
valid_email:false,
valid_name:false,
email:'',
name:'',
privacy:false,
};
this.handleChange = this.handleChange.bind(this);
this.handleCheckbox = this.handleCheckbox.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(e){
//this.props.hideModal()
const modal='trainerModal'
if(/^\d+$/.test(this.props.modalContacts[modal].contact.value)){
this.props.updateActivation(3,'holderPhone',{
value:this.props.modalContacts[modal].contact.value,
valid:true,
required:this.props.activationSteps[3].holderPhone.required
})
this.props.updateActivation(3,'referentPhone',{
value:this.props.modalContacts[modal].contact.value,
valid:true,
required:this.props.activationSteps[3].referentPhone.required
})
}
if(/^[A-Za-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/.test(this.props.modalContacts[modal].contact.value)){
this.props.updateActivation(3,'holderMail',{
value:this.props.modalContacts[modal].contact.value,
valid:true,
required:this.props.activationSteps[3].holderMail.required
})
this.props.updateActivation(3,'referentMail',{
value:this.props.modalContacts[modal].contact.value,
valid:true,
required:this.props.activationSteps[3].referentMail.required
})
this.props.updateActivation(2,'emailIntestatario',{
value:this.props.modalContacts[modal].contact.value,
valid:true,
ignore:this.props.activationSteps[2].emailIntestatario.ignore
})
}
this.props.showModal('CONTACT_CONFIRM')
}
handleCheckbox(e){
/* const checkbox= !this.state.privacy
console.log(checkbox)
this.setState({
...this.state,
privacy: checkbox,
});*/
this.props.updateModalValues('trainerModal','privacy',{
value:!this.props.modalContacts.trainerModal.privacy.value,
valid:!this.props.modalContacts.trainerModal.privacy.valid,
required:true
})
}
handleChange(e) {
const target = e.currentTarget;
console.log(e.target.value,e.target.validity.valid)
this.setState({
...this.state,
[target.name]: target.value,
['valid_'+target.name]:e.target.validity.valid,
});
}
render(){
const modal='trainerModal'
var complete=true;
for (var property in this.props.modalContacts[modal]) {
if ( this.props.modalContacts[modal].hasOwnProperty(property)) {
//console.log('check this modal',this.props.modalContacts[modal][property])
complete=complete&&( this.props.modalContacts[modal][property].valid|| !this.props.modalContacts[modal][property].required)
}
}
return(
<ReactModal
isOpen={true}
onRequestClose={() => this.props.hideModal()}
portalClassName='modal modal-mask modal_repower modal_repower__contact isOpen'
overlayClassName='modal-wrapper'
className='modal-container'
>
<div className="close_modal" onClick={() => this.props.hideModal()}><img src="https://d33wubrfki0l68.cloudfront.net/c0553300c767c895ee4900759828af6476c3e9e9/55953/img/closed_modal.svg" alt="" /></div>
<div class=" modal-header">
<img src={trainerIcon} alt="" />
<h3>Contatta personal trainer</h3>
</div>
<div class="modal-body">
<p class="modal-description">Parliamoci! Un personal trainer dell’energia ti aiuterà a costruire <br />l’offerta giusta in base alle tue necessità.</p>
<div class="modal-flex">
<ModalValidatingInput
allowNonValidInput={false}
label={'NOME O RAGIONE SOCIALE'}
pattern={"[A-zÀ-ÿ ]*"}
name={'name'}
placeholder={'Nome o ragione sociale'}
modal={'trainerModal'}
/>
<ModalValidatingInput
allowNonValidInput={false}
label={'EMAIL O NUMERO DI TELEFONO'}
pattern={"(^[A-Za-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$)||([0-9]{10,})"}
name={'contact'}
placeholder={'Email o telefono'}
modal={'trainerModal'}
/>
</div>
</div>
<div class="modal-footer">
<div class="wapper-input__modale wapper-input__modalePrivacy">
<p>
<input class="privacy" name="privacy" id="privacy" type="checkbox" onChange={this.handleCheckbox} value={this.props.modalContacts.trainerModal.privacy.value} checked={!!this.props.modalContacts.trainerModal.privacy.value}/>
<label htmlFor="privacy"><span className="isCheckbox"></span> Confermo di aver preso visione <span className=" triggher_modal privacy-modal-link" onClick={() => this.props.showModal('PRIVACY_MODAL')}>dell’informativa sulla privacy</span></label>
</p>
</div>
<button className={!(complete)
? "btn btn__gray no-events":"btn btn__red"} onClick={() => this.handleSubmit()}>
Invia
</button>
</div>
</ReactModal>
)
}
}
const mapStateToProps = state => {
return {
activationSteps: state.ProfilationSelectReducer.activationSteps,
modalContacts: state.ProfilationSelectReducer.modalContacts,
steps:state.ProfilationSelectReducer.steps,
solutions:state.ProfilationSelectReducer.solutions,
modalOpen:state.ProfilationSelectReducer.modalOpen
}};
const mapDispatchToProps = dispatch => ({
updateActivation: (index,prop,value) => dispatch(SelectActionCreators.updateActivation(index,prop,value)),
updatePropValue: (prop,value,index,complete) =>
dispatch(SelectActionCreators.changeValue(prop,value,index,complete)),
updateStoreValue: (prop,value) =>
dispatch(SelectActionCreators.changeProp(prop,value)),
hideModal: () =>
dispatch(SelectActionCreators.hideModal()),
showModal: (modalName) =>
dispatch(SelectActionCreators.showModal(modalName)),
updateModalValues: (modal,field,value) => dispatch(SelectActionCreators.updateModalValues(modal,field,value)),
});
export default connect(mapStateToProps, mapDispatchToProps)(TrainerModal);