diff --git a/packages/client/src/block-provider/hooks/index.ts b/packages/client/src/block-provider/hooks/index.ts
index 84cde3291..406942c66 100644
--- a/packages/client/src/block-provider/hooks/index.ts
+++ b/packages/client/src/block-provider/hooks/index.ts
@@ -51,27 +51,23 @@ export const useCreateActionProps = () => {
});
__parent?.service?.refresh?.();
setVisible?.(false);
- if (visible !== undefined) {
+ const onSuccess = actionSchema?.['x-action-settings']?.onSuccess;
+ if (!onSuccess?.successMessage) {
return;
}
- const onSuccess = field?.decoratorProps?.onSuccess;
- if (typeof onSuccess === 'function') {
- onSuccess({ form });
- } else {
- Modal.success({
- title: onSuccess?.successMessage || t('Submitted successfully!'),
- onOk: async () => {
- await form.reset();
- if (onSuccess?.redirecting && onSuccess?.redirectTo) {
- if (isURL(onSuccess.redirectTo)) {
- window.location.href = onSuccess.redirectTo;
- } else {
- history.push(onSuccess.redirectTo);
- }
+ Modal.success({
+ title: onSuccess?.successMessage,
+ onOk: async () => {
+ await form.reset();
+ if (onSuccess?.redirecting && onSuccess?.redirectTo) {
+ if (isURL(onSuccess.redirectTo)) {
+ window.location.href = onSuccess.redirectTo;
+ } else {
+ history.push(onSuccess.redirectTo);
}
- },
- });
- }
+ }
+ },
+ });
},
};
};
@@ -82,6 +78,7 @@ export const useUpdateActionProps = () => {
const { resource, __parent } = useBlockRequestContext();
const { setVisible } = useActionContext();
const actionSchema = useFieldSchema();
+ const history = useHistory();
return {
async onClick() {
const skipValidator = actionSchema?.['x-action-settings']?.skipValidator;
@@ -101,6 +98,22 @@ export const useUpdateActionProps = () => {
__parent?.__parent?.service?.refresh?.();
}
setVisible?.(false);
+ const onSuccess = actionSchema?.['x-action-settings']?.onSuccess;
+ if (onSuccess?.successMessage) {
+ Modal.success({
+ title: onSuccess?.successMessage,
+ onOk: async () => {
+ await form.reset();
+ if (onSuccess?.redirecting && onSuccess?.redirectTo) {
+ if (isURL(onSuccess.redirectTo)) {
+ window.location.href = onSuccess.redirectTo;
+ } else {
+ history.push(onSuccess.redirectTo);
+ }
+ }
+ },
+ });
+ }
},
};
};
diff --git a/packages/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/client/src/schema-component/antd/action/Action.Designer.tsx
index 52eb414a5..390bdb299 100644
--- a/packages/client/src/schema-component/antd/action/Action.Designer.tsx
+++ b/packages/client/src/schema-component/antd/action/Action.Designer.tsx
@@ -1,5 +1,6 @@
import { ISchema, useField, useFieldSchema } from '@formily/react';
import React from 'react';
+import { useTranslation } from 'react-i18next';
import { useDesignable } from '../..';
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
@@ -7,6 +8,7 @@ export const ActionDesigner = (props) => {
const field = useField();
const fieldSchema = useFieldSchema();
const { dn } = useDesignable();
+ const { t } = useTranslation();
const isPopupAction = ['create', 'update', 'view'].includes(fieldSchema['x-action'] || '');
return (
@@ -79,7 +81,7 @@ export const ActionDesigner = (props) => {
)}
{fieldSchema?.['x-action-settings'] && (
{
fieldSchema['x-action-settings'].skipValidator = value;
@@ -127,11 +129,66 @@ export const ActionDesigner = (props) => {
}}
/>
)}
+ {fieldSchema?.['x-action-settings'] && (
+ {
+ fieldSchema['x-action-settings']['onSuccess'] = onSuccess;
+ dn.emit('patch', {
+ schema: {
+ ['x-uid']: fieldSchema['x-uid'],
+ 'x-action-settings': fieldSchema['x-action-settings'],
+ },
+ });
+ }}
+ />
+ )}
{
- return s['x-component'] === 'Space' || s['x-component'] === 'ActionBar';
+ return s['x-component'] === 'Space' || s['x-component'].endsWith('ActionBar');
}}
/>
diff --git a/packages/client/src/schema-component/antd/form-v2/Form.Designer.tsx b/packages/client/src/schema-component/antd/form-v2/Form.Designer.tsx
index 890199e46..aaf69e203 100644
--- a/packages/client/src/schema-component/antd/form-v2/Form.Designer.tsx
+++ b/packages/client/src/schema-component/antd/form-v2/Form.Designer.tsx
@@ -1,4 +1,4 @@
-import { ISchema, useField, useFieldSchema } from '@formily/react';
+import { useField, useFieldSchema } from '@formily/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useFormBlockContext } from '../../../block-provider';
@@ -19,62 +19,6 @@ export const FormDesigner = () => {
const { visible } = useActionContext();
return (
- {
- field.decoratorProps.onSuccess = onSuccess;
- fieldSchema['x-decorator-props'] = fieldSchema['x-decorator-props'] || {};
- fieldSchema['x-decorator-props']['onSuccess'] = onSuccess;
- dn.emit('patch', {
- schema: {
- ['x-uid']: fieldSchema['x-uid'],
- 'x-decorator-props': fieldSchema['x-decorator-props'],
- },
- });
- }}
- />
{/* */}
diff --git a/packages/client/src/schema-initializer/buttons/FormActionInitializers.tsx b/packages/client/src/schema-initializer/buttons/FormActionInitializers.tsx
index c509c036e..d9a9e4bc5 100644
--- a/packages/client/src/schema-initializer/buttons/FormActionInitializers.tsx
+++ b/packages/client/src/schema-initializer/buttons/FormActionInitializers.tsx
@@ -14,6 +14,9 @@ export const FormActionInitializers = {
schema: {
'x-action-settings': {
initialValues: {},
+ onSuccess: {
+ successMessage: 'Submitted successfully!',
+ },
},
},
},
@@ -36,6 +39,9 @@ export const FormActionInitializers = {
'x-designer': 'Action.Designer',
'x-action-settings': {
initialValues: {},
+ onSuccess: {
+ successMessage: 'Submitted successfully!',
+ },
},
'x-component-props': {
useProps: '{{ useCreateActionProps }}',