start rewrite effects

This commit is contained in:
Владислав Чикалкин 2020-09-22 19:21:49 +03:00
parent bb6ff077fa
commit 3712d2c3c1
5 changed files with 31 additions and 7 deletions

View File

@ -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,

View File

@ -7,6 +7,10 @@ const propsMap = {
name: 'fullname',
value: 'leadid',
},
opportunity: {
name: 'name',
value: 'opportunityid',
},
};
export default propsMap;

View File

@ -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}`,

View File

@ -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[];

View File

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