From 18bd2d562f954caa7f38d2f62bac2456ed94ed3d Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 29 Jul 2021 13:28:00 +0300 Subject: [PATCH] merge feature/link-sub-component --- .../Calculation/lib/elements/elementsProps.ts | 28 +++++++++++++++- .../lib/fetchData/queries/ownerQuery.ts | 2 ++ .../Calculation/lib/renderSections.js | 32 +++++++++++-------- .../CalculationStore/Effects/lib/queries.js | 1 + .../Effects/reactions/index.ts | 2 ++ .../Effects/reactions/linkReactions.ts | 21 ++++++++++++ src/core/types/Calculation/Store/links.ts | 2 +- src/core/types/Entities/crmEntities.ts | 3 ++ 8 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 src/client/stores/CalculationStore/Effects/reactions/linkReactions.ts diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 8512ce3..5c84ab0 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -1,5 +1,7 @@ import DownloadOutlined from '@ant-design/icons/lib/icons/DownloadOutlined'; import InsuranceTag from 'client/Components/Calculation/InsuranceTag'; +import Link from 'client/Elements/Link'; +import { withLink } from 'client/hocs/Calculation'; import { MAX_FRANCHISE } from 'core/constants/stores/Calculation/limits'; import { currentYear } from 'core/tools/date'; import { formatMoney, formatNumber } from 'core/tools/format'; @@ -322,12 +324,36 @@ const elementsProps: TElements = { }, selectLead: { showSearch: true, + sub: { + Component: withLink(Link)({ + name: 'leadUrl', + text: 'Открыть в CRM', + urlName: 'leadUrl', + type: 'link', + }), + }, }, selectOpportunity: { showSearch: true, + sub: { + Component: withLink(Link)({ + name: 'leadUrl', + text: 'Открыть в CRM', + urlName: 'opportunityUrl', + type: 'link', + }), + }, }, selectQuote: { showSearch: true, + sub: { + Component: withLink(Link)({ + name: 'leadUrl', + text: 'Открыть в CRM', + urlName: 'quoteUrl', + type: 'link', + }), + }, }, btnCalculate: { text: 'Рассчитать график', @@ -401,7 +427,7 @@ const elementsProps: TElements = { // }, }, tableInsurance: { - tag: { + sub: { Component: InsuranceTag, }, }, diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts index 0f94ffc..6dc981a 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts @@ -19,6 +19,7 @@ const query = gql` } } evo_inn + link } selectOpportunity: opportunities( statecode: $statecode @@ -37,6 +38,7 @@ const query = gql` evo_city_fias_id } } + link } } `; diff --git a/src/client/Containers/Calculation/lib/renderSections.js b/src/client/Containers/Calculation/lib/renderSections.js index 80efe0b..80fe4f3 100644 --- a/src/client/Containers/Calculation/lib/renderSections.js +++ b/src/client/Containers/Calculation/lib/renderSections.js @@ -22,28 +22,32 @@ const ElementTitle = styled.h5` white-space: nowrap; `; +const Head = ({ sub, elementTitle }) => { + if (sub?.Component) { + return ( + + {elementTitle} + + + ); + } + return {elementTitle}; +}; + const renderElements = ({ elements }) => { return elements.map((elementName, ie) => { const elementTitle = elementsTitles[elementName]; - const { tooltip, tag, ...elementProps } = elementsProps[elementName] || {}; - - let TagComponent = () => null; - if (tag && tag.Component) { - TagComponent = tag.Component; - } + const { tooltip, sub, ...elementProps } = elementsProps[elementName] || {}; const Component = buildElement(elementName, elementProps); return ( - - {elementTitle} - - + diff --git a/src/client/stores/CalculationStore/Effects/lib/queries.js b/src/client/stores/CalculationStore/Effects/lib/queries.js index 1ce4d99..bb16eb2 100644 --- a/src/client/stores/CalculationStore/Effects/lib/queries.js +++ b/src/client/stores/CalculationStore/Effects/lib/queries.js @@ -17,4 +17,5 @@ offerprintformapi evo_regionid evo_legal_regionid evo_legal_townid +link `; diff --git a/src/client/stores/CalculationStore/Effects/reactions/index.ts b/src/client/stores/CalculationStore/Effects/reactions/index.ts index 998d83c..3247701 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/index.ts @@ -1,6 +1,7 @@ import eltReactions from './eltReactions'; import gibddReactions from './gibddReactions'; import insuranceReactions from './insuranceReactions'; +import linkReactions from './linkReactions'; import loadKpReaction from './loadKpReaction'; import otherReactions from './otherReactions'; import priceReactions from './priceReactions'; @@ -19,5 +20,6 @@ export default [ ...gibddReactions, ...eltReactions, ...insuranceReactions, + ...linkReactions, loadKpReaction, ]; diff --git a/src/client/stores/CalculationStore/Effects/reactions/linkReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/linkReactions.ts new file mode 100644 index 0000000..96a73dd --- /dev/null +++ b/src/client/stores/CalculationStore/Effects/reactions/linkReactions.ts @@ -0,0 +1,21 @@ +import { IReactionEffect } from 'core/types/Calculation/Store/effect'; +import { ElementsNames } from 'core/types/Calculation/Store/elements'; +import { LinksNames } from 'core/types/Calculation/Store/links'; + +export default ([ + { elementName: 'selectLead', urlName: 'leadUrl' }, + { elementName: 'selectOpportunity', urlName: 'opportunityUrl' }, + { elementName: 'selectQuote', urlName: 'quoteUrl' }, +] as { + elementName: ElementsNames; + urlName: LinksNames; +}[]).map(({ elementName, urlName }) => calculationStore => ({ + expression: () => { + return calculationStore.getOption(elementName); + }, + effect: targetEntity => { + const { calculationUrls } = calculationStore.stores; + const link = targetEntity?.link ?? undefined; + calculationUrls.setUrl({ name: urlName, url: link }); + }, +})) as IReactionEffect[]; diff --git a/src/core/types/Calculation/Store/links.ts b/src/core/types/Calculation/Store/links.ts index 3acea3e..eaa726e 100644 --- a/src/core/types/Calculation/Store/links.ts +++ b/src/core/types/Calculation/Store/links.ts @@ -1 +1 @@ -export type LinksNames = 'kpUrl'; +export type LinksNames = 'kpUrl' | 'leadUrl' | 'opportunityUrl' | 'quoteUrl'; diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 35a03f7..3266595 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -40,6 +40,7 @@ export interface ILead { accountidData?: IAccount; owner_domainname?: string; evo_inn?: string; + link?: string; } export interface IOpportunity { @@ -52,6 +53,7 @@ export interface IOpportunity { accountidData?: IAccount; parentaccountid?: string; evo_addproduct_types?: IEvoAddproductType[]; + link?: string; } export interface IQuote { @@ -95,6 +97,7 @@ export interface IQuote { evo_franchise?: string; evo_id_elt_osago?: string; evo_object_registration?: number; + link?: string; } export interface IEvoGraph {