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

import data from './data.json'

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

import closeIcon from '../../img/closed_modal.svg'

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


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

    this.redirect=this.redirect.bind(this)
  }

  redirect(){
    window.location.href='http://www.repower.com'
  }

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

  }


  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
    const disable= !isValid
    this.setState({
      privacy: checkbox,
      [target.name]: target.value,
      buttonDisabled: disable
    });

  }

  render(){
    
    return(
      <ReactModal
          isOpen={true}
          onRequestClose={() => this.props.hideModal()}
          portalClassName='modal modal-mask modal_repower modal_repower__contact modal_repower__contact_confirm modal-confirm isOpen'
          overlayClassName='modal-wrapper'
          className='modal-container'
        >

          <div className="close_modal" onClick={()=>this.props.updateStoreValue('modalOpen',[])}><img src={closeIcon} alt="" /></div>
          
          <div  className=" modal-header">
            <img src={greenCheck} alt="" />
            {(this.props.modalOpen[0]==='TRAINER_MODAL' || this.props.modalOpen[0]==='FURNITURE_MODAL' || this.props.modalOpen[0]==='CONTACT_MODAL') && 
              <h3> {data.modalStrings.contactConfirm.trainer_title}</h3>
            }
            {(this.props.modalOpen[0]==='SAVE_MODAL') && 
              <h3>{data.modalStrings.contactConfirm.save_title}</h3>
            }
          </div>
          {(this.props.modalOpen[0]==='TRAINER_MODAL' || this.props.modalOpen[0]==='FURNITURE_MODAL' || this.props.modalOpen[0]==='CONTACT_MODAL') && 
          <div className="modal-body">

          <p className="modal-description">{data.modalStrings.contactConfirm.trainer_text_line1}</p>

          <p className="modal-description">{data.modalStrings.contactConfirm.trainer_text_line2}</p>

            
          </div>}

          {(this.props.modalOpen[0]==='SAVE_MODAL') && 
          <div className="modal-body">

          <p className="modal-description">{data.modalStrings.contactConfirm.save_text_line1} <strong>{this.props.modalContacts.activationSaveModal.contact.value}</strong> {data.modalStrings.contactConfirm.save_text_line2}</p>


            
          </div>}

          
          <div className="modal-footer">
            <button className='btn__red' onClick={()=>this.redirect()}>Vai su Repower.com</button>
            {(this.props.modalOpen[0]==='SAVE_MODAL') && 
               <button onClick={()=> this.props.updateStoreValue('modalOpen',[])} className='btn__gray'>Ok, continua</button>
            }
          </div>
        
        
        </ReactModal>
      )
  }
}

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

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