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';