diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index 55b8d43..88fe70f 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -1,12 +1,14 @@ +/* eslint-disable implicit-arrow-linebreak */ import type { ApolloClient } from '@apollo/client'; import { gql } from '@apollo/client'; import type * as CRMTypes from 'graphql/crm.types'; import { reaction } from 'mobx'; import type RootStore from 'stores/root'; import { normalizeOptions } from 'tools/entity'; +import { makeDisposable } from 'tools/mobx'; export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { - const { $calculation } = store; + const { $calculation, $process } = store; /** * Если lead содержит данные, то в opportunity подгружается значение из поля Интереса @@ -26,33 +28,37 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl } `; - reaction( - () => $calculation.getElementValue('selectLead'), - async (leadid) => { - if (!leadid) { - $calculation.resetElementValue('selectOpportunity'); + makeDisposable( + () => + reaction( + () => $calculation.getElementValue('selectLead'), + async (leadid) => { + if (!leadid) { + $calculation.resetElementValue('selectOpportunity'); - return; - } + return; + } - const { - data: { lead }, - } = await apolloClient.query< - CRMTypes.GetOpportunityByLeadQuery, - CRMTypes.GetOpportunityByLeadQueryVariables - >({ - query: QUERY_GET_OPPORTUNITY_BY_LEAD, - variables: { - leadid, - }, - }); + const { + data: { lead }, + } = await apolloClient.query< + CRMTypes.GetOpportunityByLeadQuery, + CRMTypes.GetOpportunityByLeadQueryVariables + >({ + query: QUERY_GET_OPPORTUNITY_BY_LEAD, + variables: { + leadid, + }, + }); - if (lead?.evo_opportunityidData?.value) { - $calculation.setElementValue('selectOpportunity', lead?.evo_opportunityidData?.value); - } else { - $calculation.resetElementValue('selectOpportunity'); - } - } + if (lead?.evo_opportunityidData?.value) { + $calculation.setElementValue('selectOpportunity', lead?.evo_opportunityidData?.value); + } else { + $calculation.resetElementValue('selectOpportunity'); + } + } + ), + () => $process.has('LoadKP') ); /**