diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0015dbc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "snyk.advanced.organization": "ab823a56-a868-4c59-bdfd-555d71155955", + "snyk.advanced.autoSelectOrganization": true +} \ No newline at end of file diff --git a/README.md b/README.md index 657bea1..335ca4b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # strapi-plugin-publisher +> **Important** \ +> Do not update this Plugin until Strapi is updated to 4.11.x.\ +> Version 1.3.7 is the latest version that is working with Kitchen for the moment. + A plugin for [Strapi](https://github.com/strapi/strapi) that provides the ability to easily schedule publishing and unpublishing of any content type. [![Downloads](https://img.shields.io/npm/dm/strapi-plugin-publisher?style=for-the-badge)](https://img.shields.io/npm/dm/strapi-plugin-publisher?style=for-the-badge) diff --git a/admin/src/components/Action/ActionFooter/index.js b/admin/src/components/Action/ActionFooter/index.js index 0889ee5..9869b63 100644 --- a/admin/src/components/Action/ActionFooter/index.js +++ b/admin/src/components/Action/ActionFooter/index.js @@ -1,6 +1,7 @@ import React from 'react'; import { useIntl } from 'react-intl'; import PropTypes from 'prop-types'; +import { useCMEditViewDataManager, getYupInnerErrors } from '@strapi/helper-plugin'; import { useReactQuery } from '../../../hooks/useReactQuery'; import { getTrad } from '../../../utils/getTrad'; import { Button } from '@strapi/design-system/Button'; @@ -10,6 +11,8 @@ import Cross from '@strapi/icons/Cross'; import Write from '@strapi/icons/Write'; import Pencil from '@strapi/icons/Pencil'; import Trash from '@strapi/icons/Trash'; +import get from 'lodash/get'; +import isEmpty from 'lodash/isEmpty'; const ActionFooter = ({ mode, @@ -23,19 +26,45 @@ const ActionFooter = ({ }) => { const { formatMessage } = useIntl(); const { actionMutations } = useReactQuery(); + const { createYupSchema, allLayoutData, layout, isCreatingEntry, modifiedData, dispatch } = useCMEditViewDataManager(); // action handlers + const validateCMData = async () => { + const schema = createYupSchema( + layout, + { + components: get(allLayoutData, 'components', {}), + }, + { isCreatingEntry, isDraft: false, isFromComponent: false } + ); + let errors = {}; + + try { + await schema.validate(modifiedData, { abortEarly: false }); + } catch (err) { + errors = getYupInnerErrors(err); + } + dispatch({ + type: 'SET_FORM_ERRORS', + errors, + }); + return errors; + }; + const handleActionSave = async () => { try { if (action.id) { await actionMutations.update.mutate(action); } else { - await actionMutations.create.mutate({ - mode, - entityId, - entitySlug, - ...action, - }); + const errors = await validateCMData(); + if (isEmpty(errors)) { + await actionMutations.create.mutate({ + mode, + entityId, + entitySlug, + ...action, + }); + } } setIsDisabled(true); } catch (error) { @@ -47,8 +76,11 @@ const ActionFooter = ({ setIsDisabled(false); }; - const handleActionAdd = () => { - setIsVisible(true); + const handleActionAdd = async () => { + const errors = await validateCMData(); + if (isEmpty(errors)) { + setIsVisible(true); + } }; const handleActionDelete = async () => { @@ -63,7 +95,7 @@ const ActionFooter = ({ // add action if (!isVisible) { - const addActionButtonColor = mode === 'publish' ? 'default' : 'secondary'; + const addActionButtonColor = mode === 'publish' ? 'primary' : 'secondary'; const addActionButtonIcon = mode === 'publish' ? : ; return (