mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:25:52 +00:00
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 { 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 {
|
||||
|
@ -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={
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user