feat: 'After successful submission' only configurable in the page

This commit is contained in:
chenos 2022-04-06 20:28:56 +08:00
parent 40dbae8fbe
commit d2e5cf9651
3 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { useForm } from '@formily/react';
import { Modal } from 'antd';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { useActionContext } from '../../schema-component';
import { useBlockRequestContext, useFilterByTk } from '../BlockProvider';
@ -29,9 +30,10 @@ function isURL(string) {
export const useCreateActionProps = () => {
const form = useForm();
const { resource, __parent } = useBlockRequestContext();
const { setVisible } = useActionContext();
const { visible, setVisible } = useActionContext();
const { field } = useFormBlockContext();
const history = useHistory();
const { t } = useTranslation();
return {
async onClick() {
await form.submit();
@ -46,12 +48,12 @@ export const useCreateActionProps = () => {
}
if (typeof onSuccess === 'function') {
onSuccess({ form });
} else if (typeof onSuccess === 'object') {
} else if (visible === undefined) {
Modal.success({
title: onSuccess.successMessage,
title: onSuccess?.successMessage || t('Submitted successfully!'),
onOk: async () => {
await form.reset();
if (onSuccess.redirecting && onSuccess.redirectTo) {
if (onSuccess?.redirecting && onSuccess?.redirectTo) {
if (isURL(onSuccess.redirectTo)) {
window.location.href = onSuccess.redirectTo;
} else {

View File

@ -6,6 +6,7 @@ import { useCollection } from '../../../collection-manager';
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
import { useSchemaTemplate } from '../../../schema-templates';
import { useDesignable } from '../../hooks';
import { useActionContext } from '../action';
export const FormDesigner = () => {
const { name, title } = useCollection();
@ -15,9 +16,11 @@ export const FormDesigner = () => {
const fieldSchema = useFieldSchema();
const { dn } = useDesignable();
const { t } = useTranslation();
const { visible } = useActionContext();
return (
<GeneralSchemaDesigner template={template} title={title || name}>
<SchemaSettings.ModalItem
hidden={visible !== undefined}
title={t('After successful submission')}
initialValues={fieldSchema['x-decorator-props']?.['onSuccess']}
schema={

View File

@ -298,8 +298,11 @@ SchemaSettings.PopupItem = (props) => {
};
SchemaSettings.ModalItem = (props) => {
const { title, components, scope, effects, schema, onSubmit, initialValues, ...others } = props;
const { hidden, title, components, scope, effects, schema, onSubmit, initialValues, ...others } = props;
const options = useContext(SchemaOptionsContext);
if (hidden) {
return null;
}
return (
<SchemaSettings.Item
{...others}