From df5037d87384bf359b5d678acc67d0b6df41d898 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 12 Jul 2022 17:29:30 +0300 Subject: [PATCH] =?UTF-8?q?process/lead-opportunity:=20=D0=95=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20lead=20=D1=81=D0=BE=D0=B4=D0=B5=D1=80=D0=B6=D0=B8?= =?UTF-8?q?=D1=82=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5,=20=D1=82=D0=BE?= =?UTF-8?q?=20=D0=B2=20opportunity=20=D0=BF=D0=BE=D0=B4=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B6=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=B5=D1=81=D0=B0=20=20?= =?UTF-8?q?=20=20*=20=D0=9B=D0=B8=D0=B7=D0=B8=D0=BD=D0=B3=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=81=D0=B4=D0=B5=D0=BB=D0=BA=D0=B0=20(lead.evo?= =?UTF-8?q?=5Fopportunityid=20=E2=86=92=20opportunity),=20=20=20=20*=20?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0=20=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=8D=D1=82=D0=B0=20=D0=9B?= =?UTF-8?q?=D0=A1=20=D1=83=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=20=20=20*=20=D0=98=D0=BD=D0=B0=D1=87=D0=B5=20?= =?UTF-8?q?=20=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D1=83?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.tsx | 1 + .../__generated__/GetOpportunityByLead.ts | 30 ++++++++++ process/lead-opportunity/reactions/common.ts | 57 +++++++++++++++++++ process/lead-opportunity/reactions/index.js | 1 + 4 files changed, 89 insertions(+) create mode 100644 process/lead-opportunity/reactions/__generated__/GetOpportunityByLead.ts create mode 100644 process/lead-opportunity/reactions/common.ts diff --git a/pages/index.tsx b/pages/index.tsx index b626d31..0f0c26f 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -51,6 +51,7 @@ function Home() { */ setTimeout(() => { + leadOpportunityReactions.common(store, apolloClient); leadOpportunityReactions.urls(store, apolloClient); paymentsReactions(store, apolloClient); calculateReactions.validation(store, apolloClient); diff --git a/process/lead-opportunity/reactions/__generated__/GetOpportunityByLead.ts b/process/lead-opportunity/reactions/__generated__/GetOpportunityByLead.ts new file mode 100644 index 0000000..98c8f53 --- /dev/null +++ b/process/lead-opportunity/reactions/__generated__/GetOpportunityByLead.ts @@ -0,0 +1,30 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetOpportunityByLead +// ==================================================== + +export interface GetOpportunityByLead_lead_evo_opportunityidData { + __typename: "opportunity"; + label: string | null; + value: any | null; +} + +export interface GetOpportunityByLead_lead { + __typename: "lead"; + evo_opportunityidData: GetOpportunityByLead_lead_evo_opportunityidData | null; +} + +export interface GetOpportunityByLead { + /** + * Лизинговые сделки. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName + */ + lead: GetOpportunityByLead_lead | null; +} + +export interface GetOpportunityByLeadVariables { + leadid: any; +} diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts new file mode 100644 index 0000000..d7ed1cb --- /dev/null +++ b/process/lead-opportunity/reactions/common.ts @@ -0,0 +1,57 @@ +import type { ApolloClient } from '@apollo/client'; +import { gql } from '@apollo/client'; +import { reaction } from 'mobx'; +import type RootStore from 'stores/root'; +import { normalizeOptions } from 'tools/entity'; +import type { GetOpportunityByLead } from './__generated__/GetOpportunityByLead'; + +export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { + const { $calculation } = store; + + const QUERY_GET_OPPORTUNITY = gql` + query GetOpportunityByLead($leadid: Uuid!) { + lead(leadid: $leadid) { + evo_opportunityidData { + label: name + value: opportunityid + } + } + } + `; + + /** + * Если lead содержит данные, то в opportunity подгружается значение из поля Интереса + * Лизинговая сделка (lead.evo_opportunityid → opportunity), + * и в списке для выбора только эта ЛС указывается + * Иначе ничего не указывается + */ + reaction( + () => $calculation.getElementValue('selectLead'), + async (leadid) => { + if (!leadid) { + $calculation.resetElement('selectOpportunity'); + + return; + } + + const { + data: { lead }, + } = await apolloClient.query({ + query: QUERY_GET_OPPORTUNITY, + variables: { + leadid, + }, + }); + + if (lead?.evo_opportunityidData) { + $calculation.$options.setElementOptions( + 'selectOpportunity', + normalizeOptions([lead.evo_opportunityidData]) + ); + $calculation.setElementValue('selectOpportunity', lead.evo_opportunityidData.value); + } else { + $calculation.resetElement('selectOpportunity'); + } + } + ); +} diff --git a/process/lead-opportunity/reactions/index.js b/process/lead-opportunity/reactions/index.js index 315d0ef..179f518 100644 --- a/process/lead-opportunity/reactions/index.js +++ b/process/lead-opportunity/reactions/index.js @@ -1,2 +1,3 @@ /* eslint-disable import/prefer-default-export */ +export { default as common } from './common'; export { default as urls } from './urls';