process/lead-opportunity: make some reactions disposable

This commit is contained in:
Chika 2022-10-25 17:28:22 +03:00
parent 5b923f9de7
commit d0db6048aa

View File

@ -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<object>) {
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')
);
/**