tachybase_todo/packages/plugins/@nocobase/plugin-custom-request/src/client/initializer/CustomRequestInitializer.tsx
Dunqing 8ab69500c7
fix(custom-request): permission issues (#3306)
* fix(custom-request-plugin): cannot see custom request action in non-root role when acl doesn't set

* fix: list all roles

* feat: display all roles

* feat: support

* fix: remove unused code

* fix: options is null

* fix: translation

* fix: migration error

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2024-01-13 18:13:18 +08:00

42 lines
1.1 KiB
TypeScript

import { uid } from '@formily/shared';
import { BlockInitializer, useSchemaInitializerItem } from '@nocobase/client';
import React from 'react';
import { useCustomRequestsResource } from '../hooks/useCustomRequestsResource';
export const CustomRequestInitializer: React.FC<any> = (props) => {
const customRequestsResource = useCustomRequestsResource();
const schema = {
title: '{{ t("Custom request") }}',
'x-component': 'CustomRequestAction',
'x-action': 'customize:form:request',
'x-designer': 'CustomRequestAction.Designer',
'x-decorator': 'CustomRequestAction.Decorator',
'x-uid': uid(),
'x-action-settings': {
onSuccess: {
manualClose: false,
redirecting: false,
successMessage: '{{t("Request success")}}',
},
},
};
const itemConfig = useSchemaInitializerItem();
return (
<BlockInitializer
{...itemConfig}
item={itemConfig}
onClick={async (s) => {
// create a custom request
await customRequestsResource.create({
values: {
key: s['x-uid'],
},
});
}}
schema={schema}
/>
);
};