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



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


import greenCheck from './img/greenCheck.svg'

/*
<div className="Modal Modal-mask modal_repower Modal--save isOpen">
      <div className="Modal-wrapper">
      <div className="Modal-container" >
*/
class ContactModal extends Component {


  constructor(props) {
    super(props);

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

  handleCheckbox(e){
    const target = e.currentTarget;
   
    this.form.validateFields(target);

    
    const checkbox= !this.state.privacy
    const disable= !checkbox
    this.setState({
      name:this.state.name,
      email: this.state.email,
      privacy: checkbox,
      buttonDisabled: disable
    });

    console.log('isValid',this.state)
  }


  handleChange(e) {
    const target = e.currentTarget;
   
    this.form.validateFields(target);
   
    const isValid=this.form.fieldsStore.fields.email.warnings.size===0 && 
                  this.form.fieldsStore.fields.email.errors.size===0 &&
                  this.state.email!=='' &&
                  this.form.fieldsStore.fields.name.warnings.size===0 && 
                  this.form.fieldsStore.fields.name.errors.size===0 &&
                  this.state.name!==''
    const checkbox= this.state.privacy
    console.log('isValid',this.form.fieldsStore.fields)
    const disable= !isValid
    this.setState({
      privacy: checkbox,
      [target.name]: target.value,
      buttonDisabled: disable
    });
    console.log('isValid',this.state)
  }

  render(){
    
    return(
      <ReactModal
          isOpen={true}
          onRequestClose={() => this.props.hideModal()}
          portalClassName='modal modal-mask modal_repower modal_repower__contact modal_repower__contact_confirm 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={greenCheck} alt="" />

            <h3> Perfetto, abbiamo ricevuto la tua richiesta!</h3>
          </div>
          
          <div class="modal-body">

          <p class="modal-description">Sarai contattato da un nostro personal trainer che ti potrà guidare nella scelta di un'offerta adatta alle tue esigenze.</p>

          <p class="modal-description">Nell'attesa, scopri tutte le offerte per energia e gas nel nostro portale.</p>

            
          </div>
          <div class="modal-footer">
            <button className='btn__red'>Vai su Repower.com</button>

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