Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"snyk.advanced.organization": "ab823a56-a868-4c59-bdfd-555d71155955",
"snyk.advanced.autoSelectOrganization": true
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
50 changes: 41 additions & 9 deletions admin/src/components/Action/ActionFooter/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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 () => {
Expand All @@ -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' ? <Check /> : <Cross />;
return (
<Button
Expand Down
25 changes: 19 additions & 6 deletions admin/src/components/ActionLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ import { Box } from '@strapi/design-system/Box';
import { ActionLayoutHeader } from './ActionLayoutHeader';
import { Action } from '../Action';

const actionModes = ['publish', 'unpublish'];

const ActionLayout = () => {
const { slug, hasDraftAndPublish, isCreatingEntry } = useCMEditViewDataManager();
const {
slug: modelId,
hasDraftAndPublish,
isCreatingEntry,
initialData: { slug, publishedAt },
} = useCMEditViewDataManager();
const params = useParams();
const id = _get(params, 'id', null);
const currentEntityId = Number(id);
const isMainOfferPage = slug === '/';
const pageAlreadyPublished = publishedAt !== null;

if (!hasDraftAndPublish || isCreatingEntry) {
if (!hasDraftAndPublish || isCreatingEntry || isMainOfferPage) {
return null;
}

const actionModes = () => {
let actionModes = ['publish', 'unpublish'];
if (pageAlreadyPublished) {
actionModes = ['unpublish'];
}
return actionModes;
};

return (
<Box marginTop={4}>
<ActionLayoutHeader />
{actionModes.map((m, index) => (
<Action mode={m} key={index} entitySlug={slug} entityId={currentEntityId} />
{actionModes().map((m, index) => (
<Action mode={m} key={index} entitySlug={modelId} entityId={currentEntityId} />
))}
</Box>
);
Expand Down
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@
"url": "https://github.com/ComfortablyCoding/strapi-plugin-publisher/issues"
},
"dependencies": {
"lodash": "^4.17.21",
"lodash": "^4.17.23",
"react-query": "^3.39.3",
"yup": "^0.32.9"
},
"resolutions": {
"minimatch": "3.1.4",
"brace-expansion": "1.1.12",
"@babel/runtime": "~7.26.10",
"lodash-es": "4.17.23",
"lodash": "4.17.23",
"semver": "6.3.1",
"cross-spawn": "7.0.5",
"word-wrap": "1.2.4",
"js-yaml": "4.1.1",
"ajv": "6.14.0"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/eslint-parser": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/core": "^7.26.10",
"@babel/eslint-parser": "^7.26.10",
"@babel/preset-react": "^7.26.10",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
Loading