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 LightBox from 'react-images'; import { closeLightBoxImage, completeAction, openLightBoxImage, stepBackward, stepForward, submitChallenge, updateUnlockedSteps } from '../../redux/actions'; import { challengeSelector } from '../../redux/selectors'; import { Button, Col, Image, Row } from 'react-bootstrap'; const mapStateToProps = createSelector( challengeSelector, state => state.challengesApp.currentIndex, state => state.challengesApp.previousIndex, state => state.challengesApp.isActionCompleted, state => state.challengesApp.isLightBoxOpen, ( { challenge: { description = [] } }, currentIndex, previousIndex, isActionCompleted, isLightBoxOpen ) => ({ currentIndex, isActionCompleted, isLightBoxOpen, step: description[currentIndex], steps: description, numOfSteps: description.length, isLastStep: currentIndex + 1 >= description.length }) ); const dispatchActions = { closeLightBoxImage, completeAction, openLightBoxImage, stepBackward, stepForward, submitChallenge, updateUnlockedSteps }; const propTypes = { closeLightBoxImage: PropTypes.func.isRequired, completeAction: PropTypes.func.isRequired, currentIndex: PropTypes.number, isActionCompleted: PropTypes.bool, isLastStep: PropTypes.bool, isLightBoxOpen: PropTypes.bool, numOfSteps: PropTypes.number, openLightBoxImage: PropTypes.func.isRequired, step: PropTypes.array, steps: PropTypes.array, stepBackward: PropTypes.func, stepForward: PropTypes.func, submitChallenge: PropTypes.func.isRequired, updateUnlockedSteps: PropTypes.func.isRequired }; export class StepChallenge extends PureComponent { constructor(...args) { super(...args); this.handleLightBoxOpen = this.handleLightBoxOpen.bind(this); } handleLightBoxOpen(e) { if (!(e.ctrlKey || e.metaKey)) { e.preventDefault(); this.props.openLightBoxImage(); } } componentWillMount() { const { updateUnlockedSteps } = this.props; updateUnlockedSteps([]); } componentWillUnmount() { const { updateUnlockedSteps } = this.props; updateUnlockedSteps([]); } componentWillReceiveProps(nextProps) { const { steps, updateUnlockedSteps } = this.props; if (nextProps.steps !== steps) { updateUnlockedSteps([]); } } renderActionButton(action, completeAction) { const isApiAction = action === '#'; const buttonCopy = isApiAction ? 'Confirm' : 'Open link in new tab '; if (!action) { return null; } return (