feat: 'After successful submission' only configurable in the page
This commit is contained in:
parent
40dbae8fbe
commit
d2e5cf9651
@ -1,5 +1,6 @@
|
|||||||
import { useForm } from '@formily/react';
|
import { useForm } from '@formily/react';
|
||||||
import { Modal } from 'antd';
|
import { Modal } from 'antd';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { useActionContext } from '../../schema-component';
|
import { useActionContext } from '../../schema-component';
|
||||||
import { useBlockRequestContext, useFilterByTk } from '../BlockProvider';
|
import { useBlockRequestContext, useFilterByTk } from '../BlockProvider';
|
||||||
@ -29,9 +30,10 @@ function isURL(string) {
|
|||||||
export const useCreateActionProps = () => {
|
export const useCreateActionProps = () => {
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const { resource, __parent } = useBlockRequestContext();
|
const { resource, __parent } = useBlockRequestContext();
|
||||||
const { setVisible } = useActionContext();
|
const { visible, setVisible } = useActionContext();
|
||||||
const { field } = useFormBlockContext();
|
const { field } = useFormBlockContext();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { t } = useTranslation();
|
||||||
return {
|
return {
|
||||||
async onClick() {
|
async onClick() {
|
||||||
await form.submit();
|
await form.submit();
|
||||||
@ -46,12 +48,12 @@ export const useCreateActionProps = () => {
|
|||||||
}
|
}
|
||||||
if (typeof onSuccess === 'function') {
|
if (typeof onSuccess === 'function') {
|
||||||
onSuccess({ form });
|
onSuccess({ form });
|
||||||
} else if (typeof onSuccess === 'object') {
|
} else if (visible === undefined) {
|
||||||
Modal.success({
|
Modal.success({
|
||||||
title: onSuccess.successMessage,
|
title: onSuccess?.successMessage || t('Submitted successfully!'),
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
await form.reset();
|
await form.reset();
|
||||||
if (onSuccess.redirecting && onSuccess.redirectTo) {
|
if (onSuccess?.redirecting && onSuccess?.redirectTo) {
|
||||||
if (isURL(onSuccess.redirectTo)) {
|
if (isURL(onSuccess.redirectTo)) {
|
||||||
window.location.href = onSuccess.redirectTo;
|
window.location.href = onSuccess.redirectTo;
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@ import { useCollection } from '../../../collection-manager';
|
|||||||
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
||||||
import { useSchemaTemplate } from '../../../schema-templates';
|
import { useSchemaTemplate } from '../../../schema-templates';
|
||||||
import { useDesignable } from '../../hooks';
|
import { useDesignable } from '../../hooks';
|
||||||
|
import { useActionContext } from '../action';
|
||||||
|
|
||||||
export const FormDesigner = () => {
|
export const FormDesigner = () => {
|
||||||
const { name, title } = useCollection();
|
const { name, title } = useCollection();
|
||||||
@ -15,9 +16,11 @@ export const FormDesigner = () => {
|
|||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { visible } = useActionContext();
|
||||||
return (
|
return (
|
||||||
<GeneralSchemaDesigner template={template} title={title || name}>
|
<GeneralSchemaDesigner template={template} title={title || name}>
|
||||||
<SchemaSettings.ModalItem
|
<SchemaSettings.ModalItem
|
||||||
|
hidden={visible !== undefined}
|
||||||
title={t('After successful submission')}
|
title={t('After successful submission')}
|
||||||
initialValues={fieldSchema['x-decorator-props']?.['onSuccess']}
|
initialValues={fieldSchema['x-decorator-props']?.['onSuccess']}
|
||||||
schema={
|
schema={
|
||||||
|
@ -298,8 +298,11 @@ SchemaSettings.PopupItem = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SchemaSettings.ModalItem = (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);
|
const options = useContext(SchemaOptionsContext);
|
||||||
|
if (hidden) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<SchemaSettings.Item
|
<SchemaSettings.Item
|
||||||
{...others}
|
{...others}
|
||||||
|
Loading…
Reference in New Issue
Block a user