Skip to content

Commit

Permalink
fix(forms): fix validation issues and remove workaround 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Apr 18, 2019
1 parent 5d3a419 commit a1ab033
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/forms/sessions/create-questionnaire/submit.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import _ from 'lodash';
import validate from './validate';
import store from '../../../redux/store';
import {addNotification} from '../../../redux/actions/notification-actions';
import {createQuestionnaire} from '../../../redux/actions/session-actions';

function submit(values, dispatch, props) {
// dirty trick to get around the redux form validation issue.
// TODO: Update redux form library
let formErrors = validate(values);
let body = {
pre: {},
post: {}
};

if (_.isEmpty(formErrors)) {
if (props.config.type === 'pre') {
_.assign(body.pre, values)
dispatch(createQuestionnaire(body));
} else if (props.config.type === 'post') {
_.assign(body.post, values)
}
} else {
let notification = {
level: 3,
message: 'Some form values appear to be empty.',
};
store.dispatch(addNotification(notification));
if (props.config.type === 'pre') {
_.assign(body.pre, values);
dispatch(createQuestionnaire(body));
} else if (props.config.type === 'post') {
_.assign(body.post, values)
}
}

Expand Down

0 comments on commit a1ab033

Please sign in to comment.