SaveModal.js 6.58 KB
import React, { Component } from 'react'
import ReactModal from 'react-modal';

import greenCheck from '../../img/outlineGreenCheck.svg'
import alertError from '../../img/alert_error.svg'

import { FormWithConstraints, FieldFeedback } from 'react-form-with-constraints';
import { FieldFeedbacks, FormGroup, FormControlInput } from 'react-form-with-constraints/lib/Bootstrap4';



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

/*
<div className="Modal Modal-mask modal_repower Modal--save isOpen">
      <div className="Modal-wrapper">
      <div className="Modal-container" >
*/
class SaveModal extends Component {
  
  constructor(props) {
    super(props);

    this.state = {
      email:'',
      buttonDisabled: true
    };
    this.handleChange = this.handleChange.bind(this);
  }

   handleChange(e) {
    const target = e.currentTarget;

    this.form.validateFields(target);

    //const isValid=this.form.fieldsStore.fields.email.validationMessage==="" && this.form.fieldsStore.fields.email.dirty
   
   const isValid=this.form.fieldsStore.fields.email.warnings.size===0 && this.form.fieldsStore.fields.email.errors.size===0
    this.setState({
      [target.name]: target.value,
      buttonDisabled: !isValid
    });
  }

  render(){
    console.log('modalprops',this.props)
    return(
      <ReactModal
          isOpen={true}
          onRequestClose={() => this.props.hideModal()}
          portalClassName='modal modal-mask modal_repower modal--save 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 className="modal-header">
            <img src="https://d33wubrfki0l68.cloudfront.net/a6e0b3c4556ce07e9ed9c732fed7b8a4c981880b/eef1a/img/save.svg" alt="" />
            <h3> Salva per dopo</h3>
          </div>

          <div className="modal-body">
            <div className="modal-body-flex">
              <div className="modal-body-left">
                <p>Grazie al codice Repower puoi recuperare la configurazione e proseguire in un secondo momento con l'attivazione dell'offerta.</p>
                <div className="wrapper_input wrapper_input--repowerCode">
                  <div className="label">codice repower</div>
                  <div className="code">AZ123XX1</div>
                </div>
                <div className="wrapper-link">
                  <p className="lighter">link diretto:</p>
                  <a href="#" className="permalink">http://energiaflat.repower.com/<span>AZ123XX1</span></a>
                </div>
              </div>

              <div className="modal-body-right">
                <div>
                  <p>Scansiona il QR code con il tuo smartphone e salva la configurazione. </p>
                </div>
                <div className="wrapper-qrQode">
                  <img src="https://d33wubrfki0l68.cloudfront.net/79edbf6591a1c8d6b6289d32eab7cf5ccafc5ade/ab691/img/qrcode.png" alt="" />
                </div>
              </div>
            </div>
            <div className="modal-footer">

            <FormWithConstraints ref={formWithConstraints => this.form = formWithConstraints}
                           onSubmit={this.handleSubmit} noValidate>
              <h3>Preferisci ricevere il link via email?</h3>
              <div className="attivazione-input-ct">
                <div className="attivazione-input">
                  <div className="input-cover">
                    
                    <FormGroup for="email">
                    <FormControlInput type="email" id="modal-mail" name="email" placeholder="Email"
                            value={this.state.email} onChange={this.handleChange}
                            required minLength={5} />
                            
            
            
            
          
                    <div className="input-right">
                    <FieldFeedbacks for="email" show="all">
                      <FieldFeedback when={value => !/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value)} warning>
                          <figure class="validationError-mark">
                        <img src={alertError} />
                      </figure>

                      </FieldFeedback>
                      <FieldFeedback when={value => /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value)} warning>
                          <figure class="validation-mark">
                        <img src={greenCheck} />
                      </figure>

                      </FieldFeedback>
                      </FieldFeedbacks>
                    </div>
                    
          </FormGroup>
                  </div>

                </div>
                <button className={this.state.buttonDisabled? "btn btn__gray":"btn btn__red"}>Invia</button>
              </div>
              <div className="wrapper-checkbox">

                <input className="privacy" name="privacy" id="privacy" type="checkbox" />

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

              </div>

              </FormWithConstraints>
            </div>
          </div>
        
      
        </ReactModal>
      )
  }
}

const mapStateToProps = state => {
  return {
  steps:state.ProfilationSelectReducer.steps,
  solutions:state.ProfilationSelectReducer.solutions,
  modalOpen:state.ProfilationSelectReducer.modalOpen
}};

const mapDispatchToProps = dispatch => ({
  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)),
});

export default connect(mapStateToProps, mapDispatchToProps)(SaveModal);