From 2eb474e36271bdfb60029f257c499a63948bb075 Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 13 Jul 2022 14:44:30 +0300 Subject: [PATCH] fix prev commit [2] --- process/lead-opportunity/reactions/common.ts | 80 ++++++++++++-------- process/lead-opportunity/reactions/urls.ts | 2 + 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index 9d6e485..fa998d6 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -8,7 +8,14 @@ import type { GetOpportunityByLead } from './__generated__/GetOpportunityByLead' export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { 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({ - 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({ + 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({ - 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({ + query: QUERY_GET_OPPORTUNITY_BY_LEAD, + variables: { + leadid, + }, + }); + + if (!opportunityid && lead?.evo_opportunityidData?.value) { + $calculation.resetElementValue('selectLead'); + } + } + + if (opportunityid) { + const { data } = await apolloClient.query({ + query: QUERY_GET_LEADID_BY_OPPORTUNITY, + variables: { + opportunityid, + }, + }); + + $calculation.setElementValue('selectLead', data.opportunity?.evo_leadid); + } } ); } diff --git a/process/lead-opportunity/reactions/urls.ts b/process/lead-opportunity/reactions/urls.ts index cb98b45..cef94c6 100644 --- a/process/lead-opportunity/reactions/urls.ts +++ b/process/lead-opportunity/reactions/urls.ts @@ -16,6 +16,8 @@ export default function urlsReactions(store: RootStore, apolloClient: ApolloClie (id) => { if (!id) { $calculation.resetElementValue(linkElementName); + + return; } const timeoutId = setTimeout(() => {