Fix(challenges): reset project form on submit

This commit is contained in:
Berkeley Martinez
2016-06-21 09:49:06 -07:00
parent adb7fa96cc
commit 77be343e04
3 changed files with 22 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { reduxForm } from 'redux-form'; import { resetForm, reduxForm } from 'redux-form';
import { import {
Button, Button,
FormGroup, FormGroup,
@ -20,10 +20,15 @@ const propTypes = {
showProjectSubmit: PropTypes.func, showProjectSubmit: PropTypes.func,
fields: PropTypes.object, fields: PropTypes.object,
handleSubmit: PropTypes.func, handleSubmit: PropTypes.func,
submitChallenge: PropTypes.func submitChallenge: PropTypes.func,
resetForm: PropTypes.func
}; };
const bindableActions = { submitChallenge, showProjectSubmit }; const bindableActions = {
resetForm,
submitChallenge,
showProjectSubmit
};
const frontEndFields = [ 'solution' ]; const frontEndFields = [ 'solution' ];
const backEndFields = [ const backEndFields = [
'solution', 'solution',
@ -64,6 +69,7 @@ export function _FrontEndForm({
fields, fields,
handleSubmit, handleSubmit,
submitChallenge, submitChallenge,
resetForm,
isSubmitting, isSubmitting,
showProjectSubmit showProjectSubmit
}) { }) {
@ -73,7 +79,12 @@ export function _FrontEndForm({
return ( return (
<form <form
name='NewFrontEndProject' name='NewFrontEndProject'
onSubmit={ handleSubmit(submitChallenge)} onSubmit={
handleSubmit((value) => (
submitChallenge(value),
resetForm('NewFrontEndProject'))
)
}
> >
{ {
isSubmitting ? isSubmitting ?
@ -112,6 +123,7 @@ export function _BackEndForm({
fields: { solution, githubLink }, fields: { solution, githubLink },
handleSubmit, handleSubmit,
submitChallenge, submitChallenge,
resetForm,
isSubmitting, isSubmitting,
showProjectSubmit showProjectSubmit
}) { }) {
@ -121,7 +133,12 @@ export function _BackEndForm({
return ( return (
<form <form
name='NewBackEndProject' name='NewBackEndProject'
onSubmit={ handleSubmit(submitChallenge)} onSubmit={
handleSubmit((values) => (
submitChallenge(values),
resetForm('NewBackEndProject')
))
}
> >
{ {
isSubmitting ? isSubmitting ?

View File

@ -39,7 +39,6 @@ export class Project extends PureComponent {
isCompleted: PropTypes.bool isCompleted: PropTypes.bool
}; };
render() { render() {
const { const {
id, id,

View File

@ -12,9 +12,6 @@ import { backEndProject } from '../../../utils/challengeTypes';
import { randomCompliment } from '../../../utils/get-words'; import { randomCompliment } from '../../../utils/get-words';
import { postJSON$ } from '../../../../utils/ajax-stream'; import { postJSON$ } from '../../../../utils/ajax-stream';
// NOTE(@BerkeleyTrue): this file could benefit from some refactoring.
// lots of repeat code
function postChallenge(url, body, username) { function postChallenge(url, body, username) {
const saveChallenge$ = postJSON$(url, body) const saveChallenge$ = postJSON$(url, body)
.retry(3) .retry(3)