Skip to content

Commit

Permalink
fix validation toast notification for workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Mar 28, 2018
1 parent 2146914 commit 8e00379
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/actions/editorialWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { selectFields } from 'Reducers/collections';
import { status, EDITORIAL_WORKFLOW } from 'Constants/publishModes';
import { EditorialWorkflowError } from "ValueObjects/errors";
import { loadEntry } from './entries';
import ValidationErrorTypes from 'Constants/validationErrorTypes';

const { notifSend } = notifActions;

Expand Down Expand Up @@ -261,9 +262,22 @@ export function persistUnpublishedEntry(collection, existingUnpublishedEntry) {
return async (dispatch, getState) => {
const state = getState();
const entryDraft = state.entryDraft;
const fieldsErrors = entryDraft.get('fieldsErrors');

// Early return if draft contains validation errors
if (!entryDraft.get('fieldsErrors').isEmpty()) return Promise.reject();
if (!fieldsErrors.isEmpty()) {
const hasPresenceErrors = fieldsErrors
.some(errors => errors.some(error => error.type && error.type === ValidationErrorTypes.PRESENCE));

if (hasPresenceErrors) {
dispatch(notifSend({
message: 'Oops, you\'ve missed a required field. Please complete before saving.',
kind: 'danger',
dismissAfter: 8000,
}));
}
return Promise.reject()
}

const backend = currentBackend(state.config);
const transactionID = uuid();
Expand Down

0 comments on commit 8e00379

Please sign in to comment.