ProfilationStep1.js 3.44 KB
import React from "react";
import Select from "react-select";

import { Creatable } from "react-select";
import { AsyncCreatable } from "react-select";

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

import  LemaApi  from '../../../service/service.js'

// Prendo la lista dei prodotti
const getProductOptions = () => {
    return LemaApi.getProductOptions();
}

const getJobOptions = () => {
	console.log(LemaApi.getJobsOptions());
    return LemaApi.getJobsOptions();
}

function changeField(name, event, props) {
    var completed = true;
    if (event !== null && event.value !== "") {
        for (var property in props.step) {
            if (props.step.hasOwnProperty(property)) {
                if (
                    property !== name &&
                    property !== "isComplete" &&
                    property !== "isActive"
                ) {
                    completed = completed && props.step[property] !== "";
                }
            }
        }
    } else {
        completed = false;
    }

	let step = {...props.step};
	step[name] = event.value;
	step.isComplete = completed;
    props.updatePropValue(props.index, step);
}

const ProfilationStep1 = props => (
	<div className="ProfilationStep ProfilationStep--one" onClick={e => props.activeStep(props.index)}>
		<p className="ProfilationStep__bold">
			Costruisci in pochi secondi la tua tariffa flat, 100% online.
		</p>

		<div className="d-flex">
			<p> La mia attivit&agrave; si occupa di </p>
			<AsyncCreatable
				openOnClick={false}
				autosize={true}
				creatable={true}
				name="job"
				placeholder="placeholder"
				value={props.step.job}
				onChange={e => changeField("job", e, props)}
				loadOptions={getJobOptions}
				onFocus={e => props.activeStep(props.index)}
                promptTextCreator={(label) => ` ${label} `}
				className = "select-full-height select-z-index"
			/>

			<p>ed ho bisogno di </p>
			<Select.Async
				searchable={false}
				autosize={true}
				name="service"
				placeholder="placeholder"
				value={props.step.service}
				onChange={e => changeField("service", e, props)}
				loadOptions={getProductOptions}
				onFocus={e => props.activeStep(props.index)}
				className = "select-z-index"
			/>
		</div>
		<p className="ProfilationStep__underline" onClick={() => props.showModal('CONTACT_MODAL')}>
			Per il tuo business hai più sedi e forniture?
		</p>
	</div>
);

/*ProfilationStep1.propTypes = {
    //isComplete: PropTypes.bool.isRequired,
    //isActive: PropTypes.bool.isRequired
    step: PropTypes.object.isRequired,
    index: PropTypes.number.isRequired,
    updatePropValue: PropTypes.func.isRequired
};

export default ProfilationStep1;*/

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

const mapDispatchToProps = dispatch => ({
  /*updatePropValue: (prop,value,index,complete) => 
    dispatch(SelectActionCreators.changeValue(prop,value,index,complete)),
  updateStoreValue: (prop,value) => 
    dispatch(SelectActionCreators.changeProp(prop,value)),*/
    showModal: (modalName) => 
    dispatch(SelectActionCreators.showModal(modalName)),
});

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