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 27, 2018
1 parent 2d89cc7 commit 0beb765
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions 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 All @@ -289,7 +303,6 @@ export function persistUnpublishedEntry(collection, existingUnpublishedEntry) {
assetProxies.toJS(),
state.integrations,
];

try {
const newSlug = await persistAction.call(...persistCallArgs);
dispatch(notifSend({
Expand Down

0 comments on commit 0beb765

Please sign in to comment.