process/lead-opportunity:

если opportunity содержит данные,
    то в lead подгружается значение из поля Интерес
    выбранной карточки Лизинговая сделка (opportunity.evo_leadid)
    иначе ничего не делать
This commit is contained in:
vchikalkin 2022-07-12 17:48:44 +03:00
parent df5037d873
commit 412a34158e
2 changed files with 62 additions and 20 deletions

View File

@ -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;
}

View File

@ -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<object>) {
@ -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<GetOpportunityByLead>({
query: QUERY_GET_OPPORTUNITY,
variables: {
leadid,
},
});
return;
}
const {
data: { lead },
} = await apolloClient.query<GetOpportunityByLead>({
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<GetLeadidByOpportunity>({
query: QUERY_GET_LEADID_BY_OPPORTUNITY,
variables: {
opportunityid,
},
});
$calculation.setElementValue('selectLead', data.opportunity?.evo_leadid);
}
);
}