import React, { PropTypes } from 'react'; import classnames from 'classnames'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import PureComponent from 'react-pure-render/component'; import ReactTransitionReplace from 'react-css-transition-replace'; import { submitChallenge, goToStep } from '../../redux/actions'; import { challengeSelector } from '../../redux/selectors'; import { Button, Col, Image, Row } from 'react-bootstrap'; const transitionTimeout = 1000; const mapStateToProps = createSelector( challengeSelector, state => state.challengesApp.currentStep, state => state.challengesApp.previousStep, ({ challenge }, currentStep, previousStep) => ({ challenge, currentStep, previousStep, numOfSteps: Array.isArray(challenge.description) ? challenge.description.length : 0, isGoingForward: currentStep > previousStep }) ); const dispatchActions = { goToStep, submitChallenge }; export class StepChallenge extends PureComponent { constructor(...args) { super(...args); this.handleNextClick = this.handleNextClick.bind(this); this.handleBackClick = this.handleBackClick.bind(this); } static displayName = 'StepChallenge'; static defaultProps = { currentStep: 0, previousStep: -1 }; static propTypes = { challenge: PropTypes.object, currentStep: PropTypes.number, previousStep: PropTypes.number, isGoingForward: PropTypes.bool, goToStep: PropTypes.func, submitChallenge: PropTypes.func, numOfSteps: PropTypes.number }; handleNextClick() { const { numOfSteps, currentStep, submitChallenge, goToStep } = this.props; const isLastStep = currentStep + 1 >= numOfSteps; if (isLastStep) { return submitChallenge(); } return goToStep(currentStep + 1); } handleBackClick() { const { currentStep, goToStep } = this.props; goToStep(currentStep - 1); } renderActionButton(action) { if (!action) { return null; } return (