Files
freeCodeCamp/common/app/routes/challenges/components/project/Tool-Panel.jsx

115 lines
2.8 KiB
JavaScript
Raw Normal View History

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';
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-07-11 17:44:50 -07:00
import { toggleHelpChat } from '../../../../redux/actions';
2016-06-07 20:41:42 -07:00
2016-07-11 17:44:50 -07:00
const bindableActions = {
submitChallenge,
toggleHelpChat,
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,
(
{ challenge: { challengeType = simpleProject } },
isSignedIn,
isSubmitting
) => ({
isSignedIn,
isSubmitting,
isSimple: challengeType === simpleProject,
isFrontEnd: challengeType === frontEndProject
})
);
export class ToolPanel extends PureComponent {
static propTypes = {
isSignedIn: PropTypes.bool,
isSimple: PropTypes.bool,
isFrontEnd: PropTypes.bool,
2016-07-11 17:44:50 -07:00
isSubmitting: PropTypes.bool,
toggleHelpChat: PropTypes.func.isRequired,
openBugModal: PropTypes.func.isRequired,
submitChallenge: PropTypes.func.isRequired
2016-06-07 20:41:42 -07:00
};
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-07-11 17:44:50 -07:00
submitChallenge,
toggleHelpChat,
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'
componentClass='div'
2016-07-11 17:44:50 -07:00
onClick={ toggleHelpChat }
2016-06-07 20:41:42 -07:00
>
Help
</Button>
<Button
bsStyle='primary'
className='btn-primary-ghost btn-big'
componentClass='div'
onClick={ openBugModal }
2016-06-07 20:41:42 -07:00
>
Bug
</Button>
</ButtonGroup>
</div>
);
}
}
export default connect(
mapStateToProps,
2016-07-11 17:44:50 -07:00
bindableActions
2016-06-07 20:41:42 -07:00
)(ToolPanel);