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 ;
+ };
+ return ButtonWithStore;
+};
diff --git a/src/client/hooks/useAction.js b/src/client/hooks/useAction.js
new file mode 100644
index 0000000..ef3889b
--- /dev/null
+++ b/src/client/hooks/useAction.js
@@ -0,0 +1,7 @@
+import { useStores } from './useStores';
+
+export const useAction = ({ actionName }) => {
+ const { calculationStore } = useStores();
+ const action = calculationStore.actions[actionName];
+ return { action };
+};
diff --git a/src/client/stores/CalculationStore/Effects/action.ts b/src/client/stores/CalculationStore/Effects/action.ts
new file mode 100644
index 0000000..f8ed441
--- /dev/null
+++ b/src/client/stores/CalculationStore/Effects/action.ts
@@ -0,0 +1,10 @@
+import CalculationStore from 'client/stores/CalculationStore';
+import { TAction } from 'core/types/effect';
+
+const actions: TAction = {
+ createLead: () => {
+ console.log('createLead action');
+ },
+};
+
+export default { actions };
diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts
index ff09f96..1ca15d0 100644
--- a/src/client/stores/CalculationStore/Effects/reaction.ts
+++ b/src/client/stores/CalculationStore/Effects/reaction.ts
@@ -318,7 +318,6 @@ const reactionEffects: IReactionEffect[] = [
},
})
.then(reward_conditions => {
- console.log('reward_conditions', reward_conditions);
calculationStore.setOptions(
'selectCalcDoubleAgentRewardCondition',
reward_conditions,
@@ -360,7 +359,6 @@ const reactionEffects: IReactionEffect[] = [
},
})
.then(reward_conditions => {
- console.log('reward_conditions', reward_conditions);
calculationStore.setOptions(
'selectFinDepartmentRewardCondtion',
reward_conditions,
@@ -402,7 +400,6 @@ const reactionEffects: IReactionEffect[] = [
},
})
.then(reward_conditions => {
- console.log('reward_conditions', reward_conditions);
calculationStore.setOptions(
'selectCalcBrokerRewardCondition',
reward_conditions,
diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts
index 3aeec51..46d4dad 100644
--- a/src/client/stores/CalculationStore/index.ts
+++ b/src/client/stores/CalculationStore/index.ts
@@ -2,6 +2,7 @@ import {
modalActions,
modalData,
} from 'client/stores/CalculationStore/Data/modal';
+import actionsEffects from 'client/stores/CalculationStore/Effects/action';
import assignProperties from 'client/tools/assignProps';
import { ICalculationStore } from 'core/types/stores';
import { autorun, observable, reaction, when } from 'mobx';
@@ -19,11 +20,13 @@ import whenEffects from './Effects/when';
const CalculationStore: ICalculationStore = observable(
assignProperties(
+ {},
valuesData,
valuesActions,
tablesData,
tablesActions,
computedEffects,
+ actionsEffects,
modalData,
modalActions,
),
diff --git a/src/core/types/Calculation/components.ts b/src/core/types/Calculation/components.ts
index eda04fd..43a4f8b 100644
--- a/src/core/types/Calculation/components.ts
+++ b/src/core/types/Calculation/components.ts
@@ -1,14 +1,16 @@
-import { ElementsNames } from 'core/types/elements';
+import { ActionsNames } from 'core/types/effect';
+import { ElementsNames, ElementType } from 'core/types/elements';
import { ComputedValuesNames, ValuesNames } from 'core/types/values';
interface IElement {
- isTable?: boolean;
+ type?: ElementType;
title?: string;
Component: () => JSX.Element;
props: {
name: ElementsNames;
valueName?: ValuesNames;
computedValue?: ComputedValuesNames;
+ actionName?: ActionsNames;
[key: string]: any;
};
}
diff --git a/src/core/types/effect.ts b/src/core/types/effect.ts
index 0384c69..f2730f5 100644
--- a/src/core/types/effect.ts
+++ b/src/core/types/effect.ts
@@ -4,19 +4,28 @@ import { ICalculationStore } from './stores';
type TCommonStore = typeof CommonStore;
+export type ActionsNames = 'createLead';
+
+export type TAction = {
+ [actionName in ActionsNames]?: (
+ CalculationStore: ICalculationStore,
+ CommonStore?: TCommonStore,
+ ) => void;
+};
+
export interface IAutorunEffect {
(CalculationStore: ICalculationStore, CommonStore?: TCommonStore): () => void;
}
export interface IReactionEffect {
- (CalculationStore: ICalculationStore): {
+ (CalculationStore: ICalculationStore, CommonStore?: TCommonStore): {
expression: (r: IReactionPublic) => any;
effect: (arg: any, r: IReactionPublic) => void;
};
}
export interface IWhenEffect {
- (CalculationStore: ICalculationStore): {
+ (CalculationStore: ICalculationStore, CommonStore?: TCommonStore): {
predicate: () => boolean;
effect: Lambda;
};
diff --git a/src/core/types/elements.ts b/src/core/types/elements.ts
index a1c0d14..92970f5 100644
--- a/src/core/types/elements.ts
+++ b/src/core/types/elements.ts
@@ -136,6 +136,12 @@ export type ElementsNames =
| 'lblLead'
| 'lblOpportunity';
+export enum ElementType {
+ Default,
+ Table,
+ Button,
+}
+
export type TElements = {
[elementName in ElementsNames]?: T;
};