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 { goToStep, completeAction, submitChallenge } 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.currentIndex, state => state.challengesApp.previousIndex, state => state.challengesApp.isActionCompleted, ( { challenge: { description = [] } }, currentIndex, previousIndex, isActionCompleted ) => ({ currentIndex, isActionCompleted, step: description[currentIndex], steps: description, numOfSteps: description.length, isGoingForward: currentIndex > previousIndex }) ); const dispatchActions = { goToStep, completeAction, 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 propTypes = { currentIndex: PropTypes.number, step: PropTypes.array, steps: PropTypes.array, isActionCompleted: PropTypes.bool, isGoingForward: PropTypes.bool, numOfSteps: PropTypes.number, goToStep: PropTypes.func, completeAction: PropTypes.func, submitChallenge: PropTypes.func }; handleNextClick() { const { numOfSteps, currentIndex, submitChallenge, goToStep } = this.props; const isLastStep = currentIndex + 1 >= numOfSteps; if (isLastStep) { return submitChallenge(); } return goToStep(currentIndex + 1); } handleBackClick() { const { currentIndex, goToStep } = this.props; goToStep(currentIndex - 1); } renderActionButton(action, completeAction) { const isApiAction = action === '#'; const buttonCopy = isApiAction ? 'Confirm' : 'Open link in new tab '; if (!action) { return null; } return (