2016-06-07 20:41:42 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import PureComponent from 'react-pure-render/component';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
|
|
|
import { Button, ButtonGroup } from 'react-bootstrap';
|
|
|
|
import {
|
|
|
|
FrontEndForm,
|
|
|
|
BackEndForm
|
|
|
|
} from './Forms.jsx';
|
|
|
|
|
2016-07-11 21:54:55 -07:00
|
|
|
import { submitChallenge, openBugModal } from '../../redux/actions';
|
2016-06-07 20:41:42 -07:00
|
|
|
import { challengeSelector } from '../../redux/selectors';
|
|
|
|
import {
|
|
|
|
simpleProject,
|
|
|
|
frontEndProject
|
|
|
|
} from '../../../../utils/challengeTypes';
|
|
|
|
|
2016-11-08 17:26:58 -08:00
|
|
|
const propTypes = {
|
|
|
|
isSignedIn: PropTypes.bool,
|
|
|
|
isSimple: PropTypes.bool,
|
|
|
|
isFrontEnd: PropTypes.bool,
|
|
|
|
isSubmitting: PropTypes.bool,
|
|
|
|
helpChatRoom: PropTypes.string.isRequired,
|
|
|
|
openBugModal: PropTypes.func.isRequired,
|
|
|
|
submitChallenge: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
const mapDispatchToProps = {
|
2016-07-11 17:44:50 -07:00
|
|
|
submitChallenge,
|
2016-07-11 21:54:55 -07:00
|
|
|
openBugModal
|
2016-07-11 17:44:50 -07:00
|
|
|
};
|
2016-06-07 20:41:42 -07:00
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
challengeSelector,
|
|
|
|
state => state.app.isSignedIn,
|
|
|
|
state => state.challengesApp.isSubmitting,
|
2016-11-08 17:26:58 -08:00
|
|
|
state => state.challengesApp.helpChatRoom,
|
2016-06-07 20:41:42 -07:00
|
|
|
(
|
|
|
|
{ challenge: { challengeType = simpleProject } },
|
|
|
|
isSignedIn,
|
2016-11-08 17:26:58 -08:00
|
|
|
isSubmitting,
|
|
|
|
helpChatRoom,
|
2016-06-07 20:41:42 -07:00
|
|
|
) => ({
|
|
|
|
isSignedIn,
|
|
|
|
isSubmitting,
|
2016-11-08 17:26:58 -08:00
|
|
|
helpChatRoom,
|
2016-06-07 20:41:42 -07:00
|
|
|
isSimple: challengeType === simpleProject,
|
|
|
|
isFrontEnd: challengeType === frontEndProject
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
export class ToolPanel extends PureComponent {
|
|
|
|
renderSubmitButton(isSignedIn, submitChallenge) {
|
|
|
|
const buttonCopy = isSignedIn ?
|
|
|
|
'Submit and go to my next challenge' :
|
|
|
|
"I've completed this challenge";
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
block={ true }
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-big'
|
|
|
|
onClick={ submitChallenge }
|
|
|
|
>
|
|
|
|
{ buttonCopy } (ctrl + enter)
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
isFrontEnd,
|
|
|
|
isSimple,
|
|
|
|
isSignedIn,
|
|
|
|
isSubmitting,
|
2016-11-08 17:26:58 -08:00
|
|
|
helpChatRoom,
|
2016-07-11 17:44:50 -07:00
|
|
|
submitChallenge,
|
2016-07-11 21:54:55 -07:00
|
|
|
openBugModal
|
2016-06-07 20:41:42 -07:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const FormElement = isFrontEnd ? FrontEndForm : BackEndForm;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{
|
|
|
|
isSimple ?
|
|
|
|
this.renderSubmitButton(isSignedIn, submitChallenge) :
|
|
|
|
<FormElement isSubmitting={ isSubmitting }/>
|
|
|
|
}
|
|
|
|
<div className='button-spacer' />
|
|
|
|
<ButtonGroup justified={ true }>
|
|
|
|
<Button
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-primary-ghost btn-big'
|
2016-11-08 17:26:58 -08:00
|
|
|
componentClass='a'
|
|
|
|
href={ `https://gitter.im/freecodecamp/${helpChatRoom}` }
|
|
|
|
target='_blank'
|
2016-06-07 20:41:42 -07:00
|
|
|
>
|
|
|
|
Help
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-primary-ghost btn-big'
|
|
|
|
componentClass='div'
|
2016-07-11 21:54:55 -07:00
|
|
|
onClick={ openBugModal }
|
2016-06-07 20:41:42 -07:00
|
|
|
>
|
|
|
|
Bug
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 17:26:58 -08:00
|
|
|
ToolPanel.propTypes = propTypes;
|
|
|
|
ToolPanel.displayName = 'ToolPanel';
|
|
|
|
|
2016-06-07 20:41:42 -07:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
2016-11-08 17:26:58 -08:00
|
|
|
mapDispatchToProps
|
2016-06-07 20:41:42 -07:00
|
|
|
)(ToolPanel);
|