From 412a34158e5caa4abb0638b95b6ebd66e1062f01 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 12 Jul 2022 17:48:44 +0300 Subject: [PATCH] =?UTF-8?q?process/lead-opportunity:=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20opportunity=20=D1=81=D0=BE=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B8=D1=82=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5,=20=20=20?= =?UTF-8?q?=20=20=D1=82=D0=BE=20=D0=B2=20lead=20=D0=BF=D0=BE=D0=B4=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B6=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=20=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=B5=D1=81?= =?UTF-8?q?=20=20=20=20=20=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=9B=D0=B8=D0=B7=D0=B8=D0=BD=D0=B3=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=BA=D0=B0=20(opportunity.evo=5Fleadi?= =?UTF-8?q?d)=20=20=20=20=20=D0=B8=D0=BD=D0=B0=D1=87=D0=B5=20=D0=BD=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__generated__/GetLeadidByOpportunity.ts | 21 +++++++ process/lead-opportunity/reactions/common.ts | 61 +++++++++++++------ 2 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 process/lead-opportunity/reactions/__generated__/GetLeadidByOpportunity.ts diff --git a/process/lead-opportunity/reactions/__generated__/GetLeadidByOpportunity.ts b/process/lead-opportunity/reactions/__generated__/GetLeadidByOpportunity.ts new file mode 100644 index 0000000..9c5c103 --- /dev/null +++ b/process/lead-opportunity/reactions/__generated__/GetLeadidByOpportunity.ts @@ -0,0 +1,21 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetLeadidByOpportunity +// ==================================================== + +export interface GetLeadidByOpportunity_opportunity { + __typename: "opportunity"; + evo_leadid: any | null; +} + +export interface GetLeadidByOpportunity { + opportunity: GetLeadidByOpportunity_opportunity | null; +} + +export interface GetLeadidByOpportunityVariables { + opportunityid: any; +} diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index d7ed1cb..e9054d7 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -2,7 +2,7 @@ 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 { GetLeadidByOpportunity } from './__generated__/GetLeadidByOpportunity'; import type { GetOpportunityByLead } from './__generated__/GetOpportunityByLead'; export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { @@ -28,30 +28,51 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl reaction( () => $calculation.getElementValue('selectLead'), async (leadid) => { - if (!leadid) { - $calculation.resetElement('selectOpportunity'); + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: QUERY_GET_OPPORTUNITY, + variables: { + leadid, + }, + }); - return; - } - - const { - data: { lead }, - } = await apolloClient.query({ - query: QUERY_GET_OPPORTUNITY, - variables: { - leadid, - }, - }); - - if (lead?.evo_opportunityidData) { - $calculation.$options.setElementOptions( + $calculation.setElementValue( 'selectOpportunity', - normalizeOptions([lead.evo_opportunityidData]) + lead?.evo_opportunityidData?.value || null ); - $calculation.setElementValue('selectOpportunity', lead.evo_opportunityidData.value); } else { - $calculation.resetElement('selectOpportunity'); + $calculation.resetElementValue('selectOpportunity'); } } ); + + /** + * если opportunity содержит данные, + то в lead подгружается значение из поля Интерес + выбранной карточки Лизинговая сделка (opportunity.evo_leadid) + иначе ничего не делать + */ + const QUERY_GET_LEADID_BY_OPPORTUNITY = gql` + query GetLeadidByOpportunity($opportunityid: Uuid!) { + opportunity(opportunityid: $opportunityid) { + evo_leadid + } + } + `; + + reaction( + () => $calculation.getElementValue('selectOpportunity'), + async (opportunityid) => { + const { data } = await apolloClient.query({ + query: QUERY_GET_LEADID_BY_OPPORTUNITY, + variables: { + opportunityid, + }, + }); + + $calculation.setElementValue('selectLead', data.opportunity?.evo_leadid); + } + ); }