diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 82417b2..ec34c08 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -1,3 +1,4 @@ +import CalculationService from 'client/services/CalculationService'; import { IReactionEffect } from 'core/types/effect'; import { Status } from 'core/types/statuses'; @@ -7,11 +8,27 @@ const reactionEffects: IReactionEffect[] = [ const { values } = calculationStore; return values.lead; }, - effect: leadId => { + effect: async leadId => { const lead = calculationStore.options.selectLead?.find( x => x.value === leadId, ); + CalculationService.getEntityOptions({ + entityName: 'opportunity', + fields: undefined, + where: { opportunityid: lead?.evo_opportunityid }, + }) + .then(opportunities => { + calculationStore.setOptions('selectOpportunity', opportunities); + calculationStore.setValue( + 'opportunity', + opportunities[0].opportunityid, + ); + }) + .catch(err => { + throw err; + }); + if (leadId && lead?.evo_opportunityid) { const opportunity = calculationStore.options.selectOpportunity?.find( o => o.value === lead?.evo_opportunityid, diff --git a/src/core/Data/propsMap.js b/src/core/Data/propsMap.js index e39ab66..0d33b0c 100644 --- a/src/core/Data/propsMap.js +++ b/src/core/Data/propsMap.js @@ -7,6 +7,10 @@ const propsMap = { name: 'fullname', value: 'leadid', }, + opportunity: { + name: 'name', + value: 'opportunityid', + }, }; export default propsMap; diff --git a/src/core/tools/data.js b/src/core/tools/data.js index ac1c5c0..dc3529a 100644 --- a/src/core/tools/data.js +++ b/src/core/tools/data.js @@ -1,6 +1,10 @@ import propsMap from '../../core/Data/propsMap'; export function objectToOption(obj, entityName) { + if (!propsMap[entityName]) { + console.warn(`Warning: ${entityName} not found in propsMap!`); + return obj; + } const optionatedObject = { ...obj, name: obj[propsMap[entityName]['name']] || `Unknown ${entityName}`, diff --git a/src/core/types/Requests/Calculation.ts b/src/core/types/Requests/Calculation.ts index 56d03d5..976fc21 100644 --- a/src/core/types/Requests/Calculation.ts +++ b/src/core/types/Requests/Calculation.ts @@ -12,11 +12,10 @@ export interface IGetInitialDataResponse { export interface IGetEntity { // TODO enitity names list entityName: EntityNames; - fields: string[]; - where: { [prop: string]: any }; + //TODO: remove ? + fields?: string[]; + where?: { [prop: string]: any }; [prop: string]: any; } -export interface IGetEntityOptionsResponse { - entityOptions: IOption[]; -} +export type IGetEntityOptionsResponse = IOption[]; diff --git a/src/server/controllers/CalculationController.ts b/src/server/controllers/CalculationController.ts index 8305b9c..c0b81e2 100644 --- a/src/server/controllers/CalculationController.ts +++ b/src/server/controllers/CalculationController.ts @@ -17,7 +17,7 @@ function _getFakeEntities(entityName, fields, where) { for (let w in where) { return entity[w] === where[w]; } - return true; + return false; }); return entities; }