From 8dd1c3878ee1c64894f4378f18e04962c38d9113 Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Tue, 27 Mar 2018 15:56:39 -0400 Subject: [PATCH] fix validation toast notification for workflow --- src/actions/editorialWorkflow.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/actions/editorialWorkflow.js b/src/actions/editorialWorkflow.js index 96c2f805b8b5..9bb63df79f21 100644 --- a/src/actions/editorialWorkflow.js +++ b/src/actions/editorialWorkflow.js @@ -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; @@ -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();