MobileUpload.js 12.6 KB
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';

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);
    }

    handleCheckbox(check) {
        const checkVal = !this.state[check.checkId]
        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)

    }

    render() {

        if (this.state.showingMessage) {
            setTimeout(function () {
                this.setState({
                    ...this.state,
                    showingMessage: false
                })

            }.bind(this), 2000)
        }

        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)
        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&agrave;
                                </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={this.state.idSamefile ? 2 : 1}
                                />
                                {!this.props.idSamefile && <DocumentBox
                                    name="Carta d'identità"
                                    icon={idIcon}
                                    side="Retro"
                                    defaultFilename=''
                                    index={0}
                                    propName='idCard_back'
                                    step={this.props.activationSteps[0]}
                                    maxPhotos={this.state.idSamefile ? 2 : 1}
                                />}
                            </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={this.state.cfSamefile ? 2 : 1}
                                />
                                {!this.props.cfSamefile && <DocumentBox
                                    name="Codice fiscale"
                                    icon={cfIcon}
                                    side="Retro"
                                    defaultFilename=''
                                    index={0}
                                    propName='cfCard_back'
                                    step={this.props.activationSteps[0]}
                                    maxPhotos={this.state.cfSamefile ? 2 : 1}
                                />}
                            </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}

                                />


                            </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}
                                />

                            </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);