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); + } + ); }