import React, {Component} from 'react'; import {Col} from 'reactstrap'; import {connect} from 'react-redux'; import './style/CartStepsContainer.css'; import {fetchCartItems} from '../../actions/cart/cartActions'; import {cartTexts} from '../../constants/cartConstants'; class CartStepsContainer extends Component { constructor(props) { super(props); this.handleStepChange = this.handleStepChange.bind(this); } componentDidMount() { const isForSteps = true; this.props.dispatch(fetchCartItems(isForSteps)); } handleStepChange(stepDirection) { if(stepDirection === 'next') { if(this.props.nextStepAction) { this.props.nextStepAction(); } } else { if(this.props.prevStepAction) { this.props.prevStepAction(); } } } render() { const {cartSteps, currentStep, isLoading} = this.props; const stepsLength = cartSteps && Object.keys(cartSteps).length - 1; return ( {(cartSteps && cartSteps[currentStep] && cartSteps[currentStep].previous && !isLoading) && {this.handleStepChange('previous')}} className="prev-btn"> {cartTexts.buttons.BACK} } {cartSteps && Object.keys(cartSteps).map((stepKey, index) => {(index + 1) + ' . ' + cartSteps[stepKey].name} {stepsLength !== index &&
}
)} {(cartSteps && cartSteps[currentStep] && cartSteps[currentStep].next && !isLoading) && {this.handleStepChange('next')}} className="next-btn"> {cartTexts.buttons.NEXT} } ); } } const mapStateToProps = (state) => ({ cartItems: state.cartReducer.cartItems, cartSteps: state.cartReducer.cartSteps, currentStep: state.cartReducer.currentStep, cartDocuments: state.cartReducer.cartDocuments, nextStepAction: state.cartReducer.nextStepAction, prevStepAction: state.cartReducer.prevStepAction, isLoading: state.cartReducer.isLoading }); export default connect(mapStateToProps)(CartStepsContainer);