fix prev commit [2]

This commit is contained in:
Chika 2022-07-13 14:44:30 +03:00
parent 71650fd31d
commit 2eb474e362
2 changed files with 52 additions and 30 deletions

View File

@ -8,7 +8,14 @@ import type { GetOpportunityByLead } from './__generated__/GetOpportunityByLead'
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
const { $calculation } = store;
const QUERY_GET_OPPORTUNITY = gql`
/**
* Если lead содержит данные, то в opportunity подгружается значение из поля Интереса
* Лизинговая сделка (lead.evo_opportunityid opportunity),
* и в списке для выбора только эта ЛС указывается
* Иначе ничего не указывается
*/
const QUERY_GET_OPPORTUNITY_BY_LEAD = gql`
query GetOpportunityByLead($leadid: Uuid!) {
lead(leadid: $leadid) {
evo_opportunityidData {
@ -19,29 +26,26 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
}
`;
/**
* Если lead содержит данные, то в opportunity подгружается значение из поля Интереса
* Лизинговая сделка (lead.evo_opportunityid opportunity),
* и в списке для выбора только эта ЛС указывается
* Иначе ничего не указывается
*/
reaction(
() => $calculation.getElementValue('selectLead'),
async (leadid) => {
if (leadid) {
const {
data: { lead },
} = await apolloClient.query<GetOpportunityByLead>({
query: QUERY_GET_OPPORTUNITY,
variables: {
leadid,
},
});
if (!leadid) {
$calculation.resetElementValue('selectOpportunity');
$calculation.setElementValue(
'selectOpportunity',
lead?.evo_opportunityidData?.value || null
);
return;
}
const {
data: { lead },
} = await apolloClient.query<GetOpportunityByLead>({
query: QUERY_GET_OPPORTUNITY_BY_LEAD,
variables: {
leadid,
},
});
if (lead?.evo_opportunityidData?.value) {
$calculation.setElementValue('selectOpportunity', lead?.evo_opportunityidData?.value);
} else {
$calculation.resetElementValue('selectOpportunity');
}
@ -65,17 +69,33 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
reaction(
() => $calculation.getElementValue('selectOpportunity'),
async (opportunityid) => {
if (!opportunityid) {
return;
}
const { data } = await apolloClient.query<GetLeadidByOpportunity>({
query: QUERY_GET_LEADID_BY_OPPORTUNITY,
variables: {
opportunityid,
},
});
const leadid = $calculation.getElementValue('selectLead');
$calculation.setElementValue('selectLead', data.opportunity?.evo_leadid);
if (leadid) {
const {
data: { lead },
} = await apolloClient.query<GetOpportunityByLead>({
query: QUERY_GET_OPPORTUNITY_BY_LEAD,
variables: {
leadid,
},
});
if (!opportunityid && lead?.evo_opportunityidData?.value) {
$calculation.resetElementValue('selectLead');
}
}
if (opportunityid) {
const { data } = await apolloClient.query<GetLeadidByOpportunity>({
query: QUERY_GET_LEADID_BY_OPPORTUNITY,
variables: {
opportunityid,
},
});
$calculation.setElementValue('selectLead', data.opportunity?.evo_leadid);
}
}
);
}

View File

@ -16,6 +16,8 @@ export default function urlsReactions(store: RootStore, apolloClient: ApolloClie
(id) => {
if (!id) {
$calculation.resetElementValue(linkElementName);
return;
}
const timeoutId = setTimeout(() => {