Skip to content
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/th-secret-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Leaked Secrets Scan
on: [pull_request, push]
jobs:
security:
uses: spring-media/ccq-utils/.github/workflows/security.yml@main
51 changes: 42 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,46 @@ 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 +77,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 +96,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
26 changes: 18 additions & 8 deletions admin/src/components/ActionLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +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>
);
};

export { ActionLayout };