diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index 99639ce..e20bdd1 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -15,6 +15,7 @@ import { validatePhone, } from 'client/tools/validate'; import { ISections } from 'core/types/Calculation/components'; +import { ElementType } from 'core/types/elements'; const sections: ISections[] = [ { @@ -274,13 +275,14 @@ const sections: ISections[] = [ { elements: [ { + type: ElementType.Button, Component: Button, props: { type: 'primary', size: 'large', name: 'btnCreateLead', text: 'Создать интерес', - onClick: undefined, + actionName: 'createLead', }, }, ], @@ -1357,7 +1359,7 @@ const sections: ISections[] = [ { elements: [ { - isTable: true, + type: ElementType.Table, Component: Table, props: { name: 'tableInsurance', diff --git a/src/client/Containers/Calculation/lib/buildElement.js b/src/client/Containers/Calculation/lib/buildElement.js index c4847f8..db0c3d3 100644 --- a/src/client/Containers/Calculation/lib/buildElement.js +++ b/src/client/Containers/Calculation/lib/buildElement.js @@ -1,12 +1,24 @@ -import { withStoreValue, withTableData } from 'client/hocs/withStore'; +import { + withStoreButton, + withStoreValue, + withTableData, +} from 'client/hocs/withStore'; +import { ElementType } from 'core/types/elements'; export function buildElement({ - isTable, + type, Component: Element, props: elementProps, }) { - if (isTable) { - return withTableData(Element)(elementProps); + switch (type) { + case ElementType.Table: { + return withTableData(Element)(elementProps); + } + case ElementType.Button: { + return withStoreButton(Element)(elementProps); + } + default: { + return withStoreValue(Element)(elementProps); + } } - return withStoreValue(Element)(elementProps); } diff --git a/src/client/Elements/Button.jsx b/src/client/Elements/Button.jsx index eef3dd3..459c044 100644 --- a/src/client/Elements/Button.jsx +++ b/src/client/Elements/Button.jsx @@ -2,13 +2,15 @@ import { Button as AntButton } from 'antd'; import { Status } from 'core/types/statuses'; import React from 'react'; -const Button = ({ status, onClick, text, ...props }) => { +const Button = ({ status, action, text, ...props }) => { return ( { + if (action) action(); + }} > {text} diff --git a/src/client/hocs/withStore.js b/src/client/hocs/withStore.js index 355ca45..3509b40 100644 --- a/src/client/hocs/withStore.js +++ b/src/client/hocs/withStore.js @@ -7,6 +7,7 @@ import React from 'react'; import { useStores } from 'client/hooks/useStores'; import { useTableOptions } from 'client/hooks/useOptions'; import { useModal } from 'client/hooks/useModal'; +import { useAction } from 'client/hooks/useAction'; export const withStoreValue = Component => ({ name, @@ -113,3 +114,13 @@ export const withStoreModal = Modal => { }; return observer(ModalWithStore); }; + +export const withStoreButton = Button => ({ name, actionName, ...params }) => { + const ButtonWithStore = () => { + const { status } = useStatus(name); + const { action } = useAction({ actionName }); + + return