| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import PropTypes from 'prop-types'; | 
					
						
							| 
									
										
										
										
											2016-06-23 20:05:30 -07:00
										 |  |  | import { reduxForm } from 'redux-form'; | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   Button, | 
					
						
							|  |  |  |   FormGroup, | 
					
						
							|  |  |  |   FormControl | 
					
						
							|  |  |  | } from 'react-bootstrap'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | import { showProjectSubmit } from './redux'; | 
					
						
							| 
									
										
										
										
											2017-03-13 16:17:07 -07:00
										 |  |  | import SolutionInput from '../../Solution-Input.jsx'; | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | import { submitChallenge } from '../../redux'; | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   isValidURL, | 
					
						
							|  |  |  |   makeRequired, | 
					
						
							|  |  |  |   createFormValidator, | 
					
						
							|  |  |  |   getValidationState | 
					
						
							|  |  |  | } from '../../../../utils/form'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const propTypes = { | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  |   fields: PropTypes.object, | 
					
						
							|  |  |  |   handleSubmit: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |   isSignedIn: PropTypes.bool, | 
					
						
							|  |  |  |   isSubmitting: PropTypes.bool, | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  |   resetForm: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |   showProjectSubmit: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  |   submitChallenge: PropTypes.func | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  | const bindableActions = { | 
					
						
							|  |  |  |   submitChallenge, | 
					
						
							|  |  |  |   showProjectSubmit | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  | const frontEndFields = [ 'solution' ]; | 
					
						
							|  |  |  | const backEndFields = [ | 
					
						
							|  |  |  |   'solution', | 
					
						
							|  |  |  |   'githubLink' | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const fieldValidators = { | 
					
						
							|  |  |  |   solution: makeRequired(isValidURL) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const backEndFieldValidators = { | 
					
						
							|  |  |  |   ...fieldValidators, | 
					
						
							|  |  |  |   githubLink: makeRequired(isValidURL) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function _FrontEndForm({ | 
					
						
							|  |  |  |   fields, | 
					
						
							|  |  |  |   handleSubmit, | 
					
						
							|  |  |  |   submitChallenge, | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |   resetForm, | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |   isSubmitting, | 
					
						
							|  |  |  |   showProjectSubmit | 
					
						
							|  |  |  | }) { | 
					
						
							|  |  |  |   const buttonCopy = isSubmitting ? | 
					
						
							|  |  |  |     'Submit and go to my next challenge' : | 
					
						
							|  |  |  |     "I've completed this challenge"; | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <form | 
					
						
							|  |  |  |       name='NewFrontEndProject' | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |       onSubmit={ | 
					
						
							| 
									
										
										
										
											2016-06-23 16:57:26 -07:00
										 |  |  |         handleSubmit((value) => { | 
					
						
							|  |  |  |           submitChallenge(value); | 
					
						
							|  |  |  |           resetForm('NewFrontEndProject'); | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |       > | 
					
						
							| 
									
										
										
										
											2016-06-08 11:11:13 -07:00
										 |  |  |       { | 
					
						
							|  |  |  |         isSubmitting ? | 
					
						
							|  |  |  |           <SolutionInput | 
					
						
							|  |  |  |             placeholder='https://codepen/your-project' | 
					
						
							|  |  |  |             { ...fields } | 
					
						
							|  |  |  |           /> : | 
					
						
							|  |  |  |           null | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |       <Button | 
					
						
							|  |  |  |         block={ true } | 
					
						
							|  |  |  |         bsStyle='primary' | 
					
						
							|  |  |  |         className='btn-big' | 
					
						
							|  |  |  |         onClick={ isSubmitting ? null : showProjectSubmit } | 
					
						
							|  |  |  |         type={ isSubmitting ? 'submit' : null } | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |         { buttonCopy } (ctrl + enter) | 
					
						
							|  |  |  |       </Button> | 
					
						
							|  |  |  |     </form> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _FrontEndForm.propTypes = propTypes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const FrontEndForm = reduxForm( | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     form: 'NewFrontEndProject', | 
					
						
							|  |  |  |     fields: frontEndFields, | 
					
						
							|  |  |  |     validate: createFormValidator(fieldValidators) | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   null, | 
					
						
							|  |  |  |   bindableActions | 
					
						
							|  |  |  | )(_FrontEndForm); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function _BackEndForm({ | 
					
						
							|  |  |  |   fields: { solution, githubLink }, | 
					
						
							|  |  |  |   handleSubmit, | 
					
						
							|  |  |  |   submitChallenge, | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |   resetForm, | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |   isSubmitting, | 
					
						
							|  |  |  |   showProjectSubmit | 
					
						
							|  |  |  | }) { | 
					
						
							|  |  |  |   const buttonCopy = isSubmitting ? | 
					
						
							|  |  |  |     'Submit and go to my next challenge' : | 
					
						
							|  |  |  |     "I've completed this challenge"; | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <form | 
					
						
							|  |  |  |       name='NewBackEndProject' | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |       onSubmit={ | 
					
						
							| 
									
										
										
										
											2016-06-23 16:57:26 -07:00
										 |  |  |         handleSubmit((values) => { | 
					
						
							|  |  |  |           submitChallenge(values); | 
					
						
							|  |  |  |           resetForm('NewBackEndProject'); | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2016-06-21 09:49:06 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |       > | 
					
						
							| 
									
										
										
										
											2016-06-08 11:11:13 -07:00
										 |  |  |       { | 
					
						
							|  |  |  |         isSubmitting ? | 
					
						
							|  |  |  |           <SolutionInput | 
					
						
							|  |  |  |             placeholder='https://your-app.com' | 
					
						
							|  |  |  |             solution={ solution } | 
					
						
							|  |  |  |           /> : | 
					
						
							|  |  |  |           null | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-06-07 20:41:42 -07:00
										 |  |  |       { isSubmitting ? | 
					
						
							|  |  |  |         <FormGroup | 
					
						
							|  |  |  |           controlId='githubLink' | 
					
						
							|  |  |  |           validationState={ getValidationState(githubLink) } | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |           <FormControl | 
					
						
							|  |  |  |             name='githubLink' | 
					
						
							|  |  |  |             placeholder='https://github.com/your-username/your-project' | 
					
						
							|  |  |  |             type='url' | 
					
						
							|  |  |  |             { ...githubLink } | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </FormGroup> : | 
					
						
							|  |  |  |         null | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       <Button | 
					
						
							|  |  |  |         block={ true } | 
					
						
							|  |  |  |         bsStyle='primary' | 
					
						
							|  |  |  |         className='btn-big' | 
					
						
							|  |  |  |         onClick={ isSubmitting ? null : showProjectSubmit } | 
					
						
							|  |  |  |         type={ isSubmitting ? 'submit' : null } | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |         { buttonCopy } (ctrl + enter) | 
					
						
							|  |  |  |       </Button> | 
					
						
							|  |  |  |     </form> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | _BackEndForm.propTypes = propTypes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const BackEndForm = reduxForm( | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     form: 'NewBackEndProject', | 
					
						
							|  |  |  |     fields: backEndFields, | 
					
						
							|  |  |  |     validate: createFormValidator(backEndFieldValidators) | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   null, | 
					
						
							|  |  |  |   bindableActions | 
					
						
							|  |  |  | )(_BackEndForm); |