mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
* feat: public forms plugin * refactor: public form * refactor: parseCollectionData * refactor: parseToken * refactor: handleEditPublicForm * refactor: parseACL * refactor: enable form * refactor: copy link * refactor: edable password * refactor: qr code * refactor: create public form * refactor: create public form * refactor: bulk destroy * fix: bug * refactor: support nester form * refactor: show message under control * refactor: support bulk destroy * refactor: support bulk destroy * refactor: adapt to mobile devices * refactor: settings * refactor: locale improve * refactor: parseAcl * refactor: parseAcl * fix: bug * fix: bug * fix: bug * fix: bug * refactor: dataSourceCollectionCascaderReadPretty * fix: bug * fix: bug * fix: bug * fix: collection template * fix: style improve * refactor: locale improve * refactor: parseToken * fix: bug * style: brand style improve * refactor: settings * fix: bug * fix: bug * refactor: locale improve * refactor: locale improve * refactor: locale improve * refactor: locale improve * refactor: package.json * refactor: create form schema * refactor: create form schema * fix: bug * fix: parseToken * fix: publicFormsSchema * fix: publicFormsSchema * fix: useSubmitActionProps * fix: useSubmitActionProps * fix: password * fix: password * refactor: custom request * refactor: variable for public form * style: style improve * fix: bug * style: style improve * style: style improve * refactor: filter * refactor: locale improve * refactor: locale improve * refactor: locale improve * fix: bug --------- Co-authored-by: katherinehhh <katherine_15995@163.com>
102 lines
2.7 KiB
TypeScript
102 lines
2.7 KiB
TypeScript
/**
|
|
* This file is part of the NocoBase (R) project.
|
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
* Authors: NocoBase Team.
|
|
*
|
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
*/
|
|
|
|
import { useForm } from '@formily/react';
|
|
import { uid } from '@formily/shared';
|
|
import {
|
|
useActionContext,
|
|
useAPIClient,
|
|
useCollection,
|
|
useDataBlockRequest,
|
|
useDataBlockResource,
|
|
usePlugin,
|
|
useBlockRequestContext,
|
|
} from '@nocobase/client';
|
|
import { App as AntdApp } from 'antd';
|
|
import PluginPublicFormsClient from '..';
|
|
|
|
const initialSchema = (values, formSchema) => {
|
|
return {
|
|
type: 'void',
|
|
name: uid(),
|
|
'x-decorator': 'PublicFormMessageProvider',
|
|
properties: {
|
|
form: formSchema,
|
|
success: {
|
|
type: 'void',
|
|
'x-editable': false,
|
|
'x-toolbar-props': {
|
|
draggable: false,
|
|
},
|
|
'x-settings': 'blockSettings:markdown',
|
|
'x-component': 'Markdown.Void',
|
|
'x-decorator': 'CardItem',
|
|
'x-component-props': {
|
|
content: 'Submitted Successfully',
|
|
},
|
|
'x-decorator-props': {
|
|
name: 'markdown',
|
|
engine: 'handlebars',
|
|
title: '{{ t("After successful submission",{ns:"public-forms"})}}',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
export const useSubmitActionProps = () => {
|
|
const { setVisible } = useActionContext();
|
|
const { message } = AntdApp.useApp();
|
|
const form = useForm();
|
|
const resource = useDataBlockResource();
|
|
const collection = useCollection();
|
|
const api = useAPIClient();
|
|
const plugin = usePlugin(PluginPublicFormsClient);
|
|
const { service } = useBlockRequestContext();
|
|
|
|
return {
|
|
type: 'primary',
|
|
async onClick() {
|
|
await form.submit();
|
|
const values = form.values;
|
|
if (values[collection.filterTargetKey]) {
|
|
await resource.update({
|
|
values,
|
|
filterByTk: values[collection.filterTargetKey],
|
|
});
|
|
} else {
|
|
const key = uid();
|
|
const uiSchemaCallback = plugin.getFormSchemaByType(values.type);
|
|
const keys = values.collection.split(':');
|
|
const collection = keys.pop();
|
|
const dataSource = keys.pop() || 'main';
|
|
const schema = initialSchema(
|
|
values,
|
|
uiSchemaCallback({
|
|
collection,
|
|
dataSource,
|
|
}),
|
|
);
|
|
schema['x-uid'] = key;
|
|
await resource.create({
|
|
values: {
|
|
...values,
|
|
key,
|
|
},
|
|
});
|
|
await api.resource('uiSchemas').insert({ values: schema });
|
|
}
|
|
form.reset();
|
|
await service.refresh();
|
|
message.success('Saved successfully!');
|
|
setVisible(false);
|
|
},
|
|
};
|
|
};
|