diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index ed4b823..ed35dca 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -2,6 +2,42 @@ import { IReactionEffect } from 'core/types/effect'; import { Status } from 'core/types/statuses'; const reactionEffects: IReactionEffect[] = [ + calculationStore => ({ + expression: () => { + const { values } = calculationStore; + return values.lead; + }, + effect: leadId => { + const lead = calculationStore.options.selectLead?.find( + x => x.value === leadId, + ); + + if (leadId && lead?.evo_opportunityid) { + const opportunity = calculationStore.options.selectOpportunity?.find( + o => o.value === lead?.evo_opportunityid, + ); + if (opportunity) { + calculationStore.setValue('opportunity', opportunity.value); + } else { + calculationStore.setValue('opportunity', null); + } + } else { + calculationStore.setValue('opportunity', null); + } + + if (leadId && lead) { + calculationStore.setFilter('selectQuote', quotes => { + return quotes.filter(q => q.evo_leadid === leadId); + }); + } else { + calculationStore.setFilter('selectQuote', quotes => { + return []; + }); + calculationStore.setValue('quote', null); + } + }, + }), + calculationStore => ({ expression: () => { const { channel } = calculationStore.values; @@ -68,8 +104,8 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValue('broker', undefined); break; } - } - }) + }, + }), ]; export default reactionEffects; diff --git a/src/core/fakeData/calculation.ts b/src/core/fakeData/calculation.ts index 9a14911..544b7ed 100644 --- a/src/core/fakeData/calculation.ts +++ b/src/core/fakeData/calculation.ts @@ -289,13 +289,15 @@ const calculationFakeData: TElements = { }, { name: '150_ООО "Некромант', - id: 'nekrolead', - value: 'nekrolead', + id: 'nekroLead', + value: 'nekroLead', + evo_opportunityid: 'nekroOpportunity', }, { name: '200_ООО "Кардинал', id: 'kardinalLead', value: 'kardinalLead', + evo_opportunityid: 'kardinalOpportunity', }, ], selectOpportunity: [ @@ -326,11 +328,13 @@ const calculationFakeData: TElements = { name: '6789_ООО "Некромант"', id: 'nekroQuote', value: 'nekroQuote', + evo_leadid: 'nekroLead', }, { name: '8765_ООО "Кардинал', id: 'kardinalQuote', value: 'kardinalQuote', + evo_leadid: 'kardinalLead', }, ], selectBroker: [