MobileUpload.js
13.8 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import React, {Component} from 'react';
import DocumentBox from './components/DocumentBox'
import idIcon from '../../img/id.svg'
import cfIcon from '../../img/codice_fiscale_icon.svg'
import logo from '../../img/logo.svg'
import LightBillIcon from '../../img/electricy_icon.svg'
import GasBillIcon from '../../img/icon_document_gas.svg'
import whiteCheck from '../../img/whiteCheck.svg'
import * as SelectActionCreators from '../actions/profilationSelect'
import {connect} from 'react-redux';
import Sticky from 'react-sticky-el';
import {NavLink} from 'react-router-dom';
import LemaApi from '../../service/service.js';
import {toast} from 'react-toastify';
class MobileUpload extends Component {
constructor(props) {
super(props)
this.state = {
showingMessage: true,
idSamefile: this.props.idSamefile,
cfSamefile: this.props.cfSamefile,
isComplete: false,
scrollTop: 0
}
this.handleCheckbox = this.handleCheckbox.bind(this);
}
deleteFile = (idFile) => {
const lemaApi = new LemaApi();
lemaApi.deleteActivationFiles(idFile);
return true;
}
handleCheckbox(check) {
const checkVal = !this.state[check.checkId]
const IndexCFCI = 0;
if(checkVal)
{
var idFile = this.props.activationSteps[IndexCFCI][check.docId + "_fileId"];
if (idFile != null){
this.deleteFile(idFile);
this.props.updateActivation(IndexCFCI, check.docId + "_fileId", null);
}
}
this.setState({
...this.state,
[check.checkId]: checkVal
})
this.props.updateStoreValue(check.checkId, checkVal)
var nofile = 'NoFile'
if (!checkVal)
nofile = ''
this.props.updateActivation(0, check.docId, nofile)
}
componentWillMount()
{
var repowerCode = this.props.match.params.activationCode;
const lemaApi = new LemaApi();
lemaApi.checkActivationCode(repowerCode)
.then(response => {
this.props.updateStoreValue('activationCode', repowerCode)
})
.catch(response => {
toast.error("Codice attivazione non valido", {position: toast.POSITION.BOTTOM_CENTER});
});
}
componentWillReceiveProps(){
const stepOne = this.props.activationSteps[0]
const stepTwo = this.props.activationSteps[1]
var complete = stepOne.idCard_front !== '' && stepOne.idCard_back !== '' &&
stepOne.cfCard_front !== '' && stepOne.cfCard_back !== '' &&
stepTwo.lightBill !== '' && stepTwo.gasBill !== ''
this.props.updateStoreValue('mobileUploadComplete', complete)
}
render() {
if (this.state.showingMessage) {
setTimeout(function () {
this.setState({
...this.state,
showingMessage: false
})
}.bind(this), 2000)
}
return (
<div className='attivazione-step mobile-upload'>
<header>
<div className="bigContainer">
<div className="logo ">
<img src={logo} alt={'logo'}/>
<p className="header--payoff ">Costruisci in pochi secondi
<br />la tua tariffa flat, 100% online.
</p>
</div>
</div>
</header>
<div className='attivazione-step-left-col attivazione-steps-inner'>
<div className='attivazione-head'>
<div className="wrapper-attivazione-head">
<h2>Carica la carta d'identità e il codice fiscale dell'intestatario</h2>
</div>
<p>
Formati accettati; jpg, png, tiff e pdf
</p>
<div className='attivazione-step-body'>
<div className='attivazione-document-section '>
<h2>
Carta d'identità
</h2>
<p>
<input type="checkbox" name="samefile" id="idCard" className='samefile'
onChange={() => this.handleCheckbox({
checkId: 'idSamefile',
docId: 'idCard_back'
})} value={this.props.idSamefile} checked={!!this.props.idSamefile}/>
<label htmlFor="idCard"><span className="isCheckbox"></span>Fronte e retro nello
stesso file</label>
</p>
</div>
<ul className='attivazione-doc-list'>
<DocumentBox
name="Carta d'identità"
icon={idIcon}
side={this.state.idSamefile ? 'Fronte e retro' : 'Fronte'}
defaultFilename=''
index={0}
propName='idCard_front'
step={this.props.activationSteps[0]}
maxPhotos={1}
maxFileSize={4}
/>
{!this.props.idSamefile && <DocumentBox
name="Carta d'identità"
icon={idIcon}
side="Retro"
defaultFilename=''
index={0}
propName='idCard_back'
step={this.props.activationSteps[0]}
maxPhotos={1}
maxFileSize={4}
/>}
</ul>
<div className='attivazione-document-section attivazione-document-section__cf'>
<h2>
Codice fiscale
</h2>
<p>
<input type="checkbox"
name="samefile"
id="cfCard"
className='samefile'
onChange={() => this.handleCheckbox({
checkId: 'cfSamefile',
docId: 'cfCard_back'
})}
value={this.props.cfSamefile}
checked={!!this.props.cfSamefile}/>
<label htmlFor="cfCard"><span className="isCheckbox"></span>Fronte e retro nello
stesso file</label>
</p>
</div>
<ul className='attivazione-doc-list'>
<DocumentBox
name="Codice fiscale"
icon={cfIcon}
side={this.state.cfSamefile ? 'Fronte e retro' : 'Fronte'}
defaultFilename=''
index={0}
propName='cfCard_front'
step={this.props.activationSteps[0]}
maxPhotos={1}
maxFileSize={4}
/>
{!this.props.cfSamefile && <DocumentBox
name="Codice fiscale"
icon={cfIcon}
side="Retro"
defaultFilename=''
index={0}
propName='cfCard_back'
step={this.props.activationSteps[0]}
maxPhotos={1}
maxFileSize={4}
/>}
</ul>
{this.props.steps[0].service !== 'gas' &&
<div className='attivazione-document-section attivazione-document-section_bTop'>
<h2>
Carica bolletta elettricità
</h2>
<p>
Puoi caricare la bolletta nei seguenti formati: jpg, png, tiff, pdf o zip.
</p>
</div>}
{this.props.steps[0].service !== 'gas' &&
<ul className='attivazione-doc-list attivazione-doc-list__halfWImg'>
<DocumentBox
name="Bolletta elettricità"
icon={LightBillIcon}
side=''
defaultFileName="Sono necessarie tutte le pagine della tua ultima bolletta"
index={1}
propName='lightBill'
step={this.props.activationSteps[1]}
maxPhotos={4}
maxFileSize={4}
/>
</ul>}
{this.props.steps[0].service !== 'light' && <div className='attivazione-document-section'>
<h2>
Carica bolletta gas
</h2>
<p>
Puoi caricare la bolletta nei seguenti formati: jpg, png, tiff, pdf o zip.
</p>
</div>}
{this.props.steps[0].service !== 'light' &&
<ul className='attivazione-doc-list attivazione-doc-list--noBorderTop attivazione-doc-list__halfWImg'>
<DocumentBox
name="Bolletta gas"
icon={GasBillIcon}
side=''
defaultFileName="Sono necessarie tutte le pagine della tua ultima bolletta"
index={1}
propName='gasBill'
step={this.props.activationSteps[1]}
maxPhotos={4}
maxFileSize={4}
/>
</ul>}
</div>
</div>
</div>
<Sticky className='mobileStickyButton' mode='bottom' boundaryElement='.attivazione-step'
hideOnBoundaryHit={true} bottomOffset={80}>
{!this.props.mobileUploadComplete &&
<button className={this.props.mobileUploadComplete ? "btn__red" : "btn__grayLighter no-events"}>
Prosegui</button>
}
{this.props.mobileUploadComplete &&
<NavLink to={`/mobile-upload-loader`} activeClassName="active">
<button className={this.props.mobileUploadComplete ? "btn__red" : "btn__grayLighter no-events"}>
Prosegui
</button>
</NavLink>}
</Sticky>
<Sticky mode='bottom' boundaryElement='.attivazione-step'>
<div className={this.state.showingMessage ? "connection-success showing" : "connection-success"}>
<figure><img src={whiteCheck} alt=""/></figure>
<p>Connessione stabilita con successo</p>
</div>
</Sticky>
</div>
)
}
}
const mapStateToProps = state => {
return {
steps: state.ProfilationSelectReducer.steps,
activeStep: state.ProfilationSelectReducer.activeStep || 0,
activationSteps: state.ProfilationSelectReducer.activationSteps,
idSamefile: state.ProfilationSelectReducer.idSamefile,
cfSamefile: state.ProfilationSelectReducer.cfSamefile,
mobileUploadComplete: state.ProfilationSelectReducer.mobileUploadComplete
}
};
const mapDispatchToProps = dispatch => ({
updateStoreValue: (prop, value) =>
dispatch(SelectActionCreators.changeProp(prop, value)),
updatePropValue: (steps, activeStep) => dispatch(SelectActionCreators.changeValue(steps, activeStep)),
updateActivation: (index, prop, value) => dispatch(SelectActionCreators.updateActivation(index, prop, value))
});
export default connect(mapStateToProps, mapDispatchToProps)(MobileUpload);