ActivationStep1.js 9.11 KB
import React, { Component } from 'react';
import DocumentBox from '../components/DocumentBox'
import CheckBox from '../components/CheckBox'

import stepOne from '../../../img/stepone.svg'
import greenCheck from '../../../img/outlineGreenCheck.svg'
import idIcon from '../../../img/id.svg'
import cfIcon from '../../../img/codice_fiscale_icon.svg'

import RightBox from '../components/RightBox'
import Sticky from 'react-sticky-el';

import data from '../data.json'

import * as SelectActionCreators from '../../actions/profilationSelect'
import {connect} from 'react-redux';
import  LemaApi  from '../../../service/service.js';

class ActivationStep1 extends Component{

	constructor(props){
		super(props)
		this.state={
			idSamefile:this.props.idSamefile,
			cfSamefile:this.props.cfSamefile,
			isComplete: false,
			scrollTop:0
		}
		this.handleCheckbox = this.handleCheckbox.bind(this);
		this.nextStep = this.nextStep.bind(this);
	}

	nextStep(){
		this.setState({
			...this.state,
			scrollTop:0
		})
		
		this.props.updateStoreValue('showSessionMessage',false)
		
		this.props.updateActivation(this.props.index,'isActive',false)
		this.props.updateActivation(this.props.index+1,'isActive',true)
		this.props.updateStoreValue('activationActiveStep',1)
		
	}

	deleteFile = (idFile) => {
        
        const lemaApi = new LemaApi();
        lemaApi.deleteActivationFiles(idFile);
        
        return true;
    }

	handleCheckbox(check){
		
		const checkVal=!this.state[check.checkId]

		if(checkVal)
		{			
			var idFile = this.props.activationSteps[this.props.index][check.docId + "_fileId"];
			if (idFile != null){
				this.deleteFile(idFile);
				this.props.updateActivation(this.props.index, 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(this.props.index,check.docId,nofile)

		var complete=checkVal;
			for (var property in this.props.step) {
		    		if (this.props.step.hasOwnProperty(property)) {

		       	 if(property!=='isComplete'&&property!=='isActive' && property!==check.docId){
		        		complete=complete&&this.props.step[property]!==''
		        	}
		   	 }

			}
		this.props.updateActivation(this.props.index,'isComplete',complete)

	}

	render() {

		

		const activationStep=this.props.activationSteps[this.props.index]
		const loading=activationStep.idCard_front_loading||
				activationStep.idCard_back_loading||
				activationStep.cfCard_front_loading||
				activationStep.cfCard_back_loading

		var stepClass='attivazione-step attivazione-step-1'
		if(this.props.step.isActive)
		{
			stepClass=stepClass+' open'
		}
		else
		{
			stepClass=stepClass+' closed'
		}
		if(this.props.step.isComplete)
		{
			stepClass=stepClass+' complete'
		}
		return(
			<div id='activation-step1' className={stepClass}>
				<div className='attivazione-step-left-col attivazione-steps-inner'>



				<div className='attivazione-head'>
					<div className="wrapper-attivazione-head">
				    <figure>
				       {(this.props.step.isComplete && !this.props.step.isActive)&& <img className="attivazione-head-step-icon" src={greenCheck} alt='' />}
				       {(!this.props.step.isComplete || this.props.step.isActive) && <img className="attivazione-head-step-icon" src={stepOne} alt='' />}
				    </figure>
				  <h2>{data.activationStrings.activationSteps[1].title}</h2>
					</div>
				  <h2 className='edit-step' data-step-id='1' onClick={() => this.props.editStep(this.props.index)}>Modifica</h2>
				 { (this.props.step.isActive && window.innerWidth<768) &&
				  <p className="subHeading">
				        {data.activationStrings.activationSteps[1].subTitle_mobile}
				   </p>
				}
				 { (this.props.step.isActive && window.innerWidth>=768) &&
				<p>
					{data.activationStrings.activationSteps[1].subTitle1}
					<br/>{data.activationStrings.activationSteps[1].subTitle2}
				</p>}

				</div>
				<div className='attivazione-step-body'>
				 	<div className='attivazione-document-section '>
				 	<h2>
				            {data.activationStrings.activationSteps[1].idTitle}
				        </h2>
				        {window.innerWidth>=768 &&
				        <p>
				        	{data.activationStrings.activationSteps[1].idSubTitle}
				        </p>}
				        <CheckBox name='idSamefile' value={this.props.idSamefile} onChange={() => this.handleCheckbox({checkId:'idSamefile',docId:'idCard_back'})}>
				        	{data.activationStrings.activationSteps[1].sameFileCheckbox}
				        </CheckBox>
				 	</div>
				 	<ul className='attivazione-doc-list'>
            				<DocumentBox 
            					name="Carta d'identità"
            					icon={idIcon}
            					side={this.state.idSamefile? 'Fronte e retro':'Fronte'}
            					defaultFilename=''
            					index={this.props.index}
            					propName='idCard_front'
            					step={this.props.step}
            					maxPhotos={1}
            					maxFileSize={4}
            					multiple={false}
            					showCam={this.props.showCam}
            				/>
            				{!this.props.idSamefile &&<DocumentBox 
            					name="Carta d'identità"
            					icon={idIcon}
            					side="Retro"
            					defaultFilename=''
            					index={this.props.index}
            					propName='idCard_back'
            					step={this.props.step}
            					maxPhotos={1}
            					maxFileSize={4}
            					multiple={false}
            					showCam={this.props.showCam}
            				/>}
            			</ul>

            			<div className='attivazione-document-section attivazione-document-section__cf'>
				 	<h2>
				            {data.activationStrings.activationSteps[1].cfTitle}
				        </h2>
				        {window.innerWidth>=768 &&
				        <p>
				        	{data.activationStrings.activationSteps[1].cfSubTitle} 
				        </p>}
				        
				        <CheckBox name='cfSamefile' value={this.props.cfSamefile} onChange={() => this.handleCheckbox({checkId:'cfSamefile',docId:'cfCard_back'})}>
				        	{data.activationStrings.activationSteps[1].sameFileCheckbox}
				        </CheckBox>
				 	</div>
				 	<ul className='attivazione-doc-list'>
            				<DocumentBox 
            					name="Codice fiscale"
            					icon={cfIcon}
            					side={this.state.cfSamefile? 'Fronte e retro':'Fronte'}
            					defaultFilename=''
            					index={this.props.index}
            					propName='cfCard_front'
            					step={this.props.step}
            					maxPhotos={1}
            					maxFileSize={4}
            					showCam={this.props.showCam}
            				/>
            				{!this.props.cfSamefile &&<DocumentBox 
            					name="Codice fiscale"
            					icon={cfIcon}
            					side="Retro"
            					defaultFilename=''
            					index={this.props.index}
            					propName='cfCard_back'
            					step={this.props.step}
            					maxPhotos={1}
            					maxFileSize={4}
            					showCam={this.props.showCam}
            				/>}
            			</ul>
				</div>
				{
					this.props.step.isActive && window.innerWidth>=768 &&
					<button className={(this.props.step.isComplete && !loading)? "btn__red":"btn__grayLighter no-events"} onClick={() => this.nextStep()} >Prosegui</button>
				}

				{
					this.props.step.isActive && window.innerWidth<768 &&
					<Sticky className='activation-mobileStickyButton' mode='bottom' boundaryElement='.attivazione-step'
                        hideOnBoundaryHit={true} bottomOffset={80}>
						<button className={(this.props.step.isComplete && !loading)? "btn__red":"btn__grayLighter no-events"} onClick={() => this.nextStep()} >Prosegui</button>
					</Sticky>
				}
				
			</div>
			{window.innerWidth>1024 &&
			<Sticky className='right-box-sticky' mode='top' boundaryElement='.attivazione-step-1' hideOnBoundaryHit={false} topOffset={-120} bottomOffset={0}>
				<div className='right-box-padding'>
				<RightBox mode='NO_DOCUMENTS' stepIndex={0} loadingDocs={loading} />
				</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,
  }
};

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)(ActivationStep1);