|
1 | 1 | import importMessages from "./locale"; |
2 | | -import { CancelButton, SubmitButton } from "@kne/react-form-antd"; |
3 | | -import { IntlProvider, FormattedMessage } from "@components/Intl"; |
4 | | -import { Form } from "./formModule"; |
| 2 | +import {CancelButton, SubmitButton} from "@kne/react-form-antd"; |
| 3 | +import {IntlProvider, FormattedMessage} from "@components/Intl"; |
| 4 | +import {Form} from "./formModule"; |
5 | 5 | import classnames from "classnames"; |
6 | 6 | import style from "./style.module.scss"; |
7 | 7 |
|
8 | 8 | const localeModuleName = "FormInfo"; |
9 | 9 |
|
10 | 10 | const computedCommonProps = ({ |
11 | | - className, |
12 | | - withDecorator, |
13 | | - footerButtons, |
14 | | - formProps, |
15 | | - cancelText, |
16 | | - saveText, |
17 | | - autoClose, |
18 | | - ...modalProps |
19 | | -}) => { |
20 | | - return { |
21 | | - ...modalProps, |
22 | | - footerButtons: footerButtons || [ |
23 | | - { |
24 | | - children: ( |
25 | | - <IntlProvider |
26 | | - importMessages={importMessages} |
27 | | - moduleName={localeModuleName} |
28 | | - > |
29 | | - {cancelText || ( |
30 | | - <FormattedMessage id={"Cancel"} moduleName={localeModuleName} /> |
31 | | - )} |
32 | | - </IntlProvider> |
33 | | - ), |
34 | | - ButtonComponent: CancelButton, |
35 | | - }, |
36 | | - { |
37 | | - type: "primary", |
38 | | - children: ( |
39 | | - <IntlProvider |
40 | | - importMessages={importMessages} |
41 | | - moduleName={localeModuleName} |
42 | | - > |
43 | | - {saveText || ( |
44 | | - <FormattedMessage id={"Save"} moduleName={localeModuleName} /> |
45 | | - )} |
46 | | - </IntlProvider> |
47 | | - ), |
48 | | - ButtonComponent: SubmitButton, |
49 | | - autoClose: false, |
50 | | - }, |
51 | | - ], |
52 | | - withDecorator: (render, args) => { |
53 | | - const innerRender = (props) => { |
54 | | - const { onSubmit, ..._formProps } = |
55 | | - typeof formProps === "function" ? formProps(props) : formProps; |
56 | | - return ( |
57 | | - <Form |
58 | | - {..._formProps} |
59 | | - onSubmit={async (data, ...args) => { |
60 | | - const res = |
61 | | - onSubmit && |
62 | | - (await onSubmit(data, Object.assign({}, props), ...args)); |
63 | | - if (res !== false) { |
64 | | - autoClose && props.close(); |
65 | | - } |
66 | | - }} |
67 | | - > |
68 | | - <IntlProvider importMessages={importMessages} moduleName="FormInfo"> |
69 | | - {render(props)} |
70 | | - </IntlProvider> |
71 | | - </Form> |
72 | | - ); |
73 | | - }; |
74 | | - return typeof withDecorator === "function" |
75 | | - ? withDecorator(innerRender, args) |
76 | | - : innerRender(args); |
77 | | - }, |
78 | | - className: classnames(className, style["form-outer"]), |
79 | | - }; |
| 11 | + className, |
| 12 | + withDecorator, |
| 13 | + footerButtons, |
| 14 | + formProps, |
| 15 | + cancelText, |
| 16 | + saveText, |
| 17 | + autoClose, |
| 18 | + ...modalProps |
| 19 | + }) => { |
| 20 | + return { |
| 21 | + ...modalProps, footerButtons: footerButtons || [{ |
| 22 | + children: (<IntlProvider |
| 23 | + importMessages={importMessages} |
| 24 | + moduleName={localeModuleName} |
| 25 | + > |
| 26 | + {cancelText || (<FormattedMessage id={"Cancel"} moduleName={localeModuleName}/>)} |
| 27 | + </IntlProvider>), ButtonComponent: CancelButton, |
| 28 | + }, { |
| 29 | + type: "primary", children: (<IntlProvider |
| 30 | + importMessages={importMessages} |
| 31 | + moduleName={localeModuleName} |
| 32 | + > |
| 33 | + {saveText || (<FormattedMessage id={"Save"} moduleName={localeModuleName}/>)} |
| 34 | + </IntlProvider>), ButtonComponent: SubmitButton, autoClose: false, |
| 35 | + },], withDecorator: (render, args) => { |
| 36 | + const innerRender = (props) => { |
| 37 | + const { |
| 38 | + onSubmit, ..._formProps |
| 39 | + } = Object.assign({}, typeof formProps === "function" ? formProps(props) : formProps); |
| 40 | + return (<Form |
| 41 | + {..._formProps} |
| 42 | + onSubmit={async (data, ...args) => { |
| 43 | + const res = onSubmit && (await onSubmit(data, Object.assign({}, props), ...args)); |
| 44 | + if (res !== false) { |
| 45 | + autoClose && props.close(); |
| 46 | + } |
| 47 | + }} |
| 48 | + > |
| 49 | + <IntlProvider importMessages={importMessages} moduleName="FormInfo"> |
| 50 | + {render(props)} |
| 51 | + </IntlProvider> |
| 52 | + </Form>); |
| 53 | + }; |
| 54 | + return typeof withDecorator === "function" ? withDecorator(innerRender, args) : innerRender(args); |
| 55 | + }, className: classnames(className, style["form-outer"]), |
| 56 | + }; |
80 | 57 | }; |
81 | 58 |
|
82 | 59 | export default computedCommonProps; |
0 commit comments