From 8ab9268fe5b55f58f110fae731034e4d59ae029f Mon Sep 17 00:00:00 2001 From: Luca Esposito Date: Thu, 21 Sep 2023 09:40:14 +0200 Subject: [PATCH 1/6] updated readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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) From d6d7bea195518693d2e54622e7a018cc80326470 Mon Sep 17 00:00:00 2001 From: Luca Esposito Date: Thu, 21 Sep 2023 14:21:24 +0200 Subject: [PATCH 2/6] re-added lost commit: "use correct slug for entity" --- admin/src/components/ActionLayout/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/src/components/ActionLayout/index.js b/admin/src/components/ActionLayout/index.js index f7989b8..05d3877 100644 --- a/admin/src/components/ActionLayout/index.js +++ b/admin/src/components/ActionLayout/index.js @@ -9,7 +9,7 @@ import { Action } from '../Action'; const actionModes = ['publish', 'unpublish']; const ActionLayout = () => { - const { slug, hasDraftAndPublish, isCreatingEntry } = useCMEditViewDataManager(); + const { slug: modelId, hasDraftAndPublish, isCreatingEntry } = useCMEditViewDataManager(); const params = useParams(); const id = _get(params, 'id', null); const currentEntityId = Number(id); @@ -22,7 +22,7 @@ const ActionLayout = () => { {actionModes.map((m, index) => ( - + ))} ); From 37ad4989554a4562a1e8206cceb9df2c6724d9c0 Mon Sep 17 00:00:00 2001 From: Luca Esposito Date: Thu, 21 Sep 2023 14:37:52 +0200 Subject: [PATCH 3/6] re-added lost commit: "add custom validation" --- .../components/Action/ActionFooter/index.js | 50 +++++++++++++++---- admin/src/components/ActionLayout/index.js | 23 +++++++-- 2 files changed, 59 insertions(+), 14 deletions(-) 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 (