fix agents & elements status
This commit is contained in:
parent
7916979ca8
commit
121f654137
@ -2,6 +2,7 @@ import initialFilters from 'client/stores/CalculationStore/config/initialFilters
|
||||
import initialOptions from 'client/stores/CalculationStore/config/initialOptions';
|
||||
import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses';
|
||||
import initialValues from 'client/stores/CalculationStore/config/initialValues';
|
||||
import { merge } from 'lodash';
|
||||
|
||||
const valuesData = {
|
||||
values: initialValues,
|
||||
@ -43,7 +44,7 @@ const valuesActions = {
|
||||
this.options[elementName] = options;
|
||||
},
|
||||
applyOptions(options) {
|
||||
this.options = { ...this.options, ...options };
|
||||
this.options = merge(this.options, options);
|
||||
},
|
||||
|
||||
getFilter(elementName) {
|
||||
|
||||
@ -2,10 +2,12 @@ import requestReactions from './requestReactions';
|
||||
import otherReactions from './otherReactions';
|
||||
import tablesReactions from './tablesReactions';
|
||||
import loadKpReaction from './loadKpReaction';
|
||||
import statusReactions from './statusReactions';
|
||||
|
||||
export default [
|
||||
...otherReactions,
|
||||
...requestReactions,
|
||||
...tablesReactions,
|
||||
...statusReactions,
|
||||
loadKpReaction,
|
||||
];
|
||||
|
||||
@ -114,14 +114,10 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
|
||||
],
|
||||
});
|
||||
|
||||
Object.keys(options).forEach(elementName => {
|
||||
if (Array.isArray(options[elementName])) {
|
||||
calculationStore.setOptions(elementName, options[elementName]);
|
||||
} else {
|
||||
calculationStore.setOptions(elementName, [options[elementName]]);
|
||||
}
|
||||
calculationStore.setStatus(elementName, ElementStatus.Default);
|
||||
});
|
||||
calculationStore.applyOptions({
|
||||
...options,
|
||||
selectDealerBroker: [options.selectDealerBroker],
|
||||
});
|
||||
|
||||
calculationStore.setTableRows(
|
||||
'tableInsurance',
|
||||
|
||||
@ -907,6 +907,24 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { dealerRewardCondition, dealerPerson } = calculationStore.values;
|
||||
return [dealerRewardCondition, dealerPerson];
|
||||
},
|
||||
effect: ([dealerRewardConditionId, dealerPersonId]) => {
|
||||
if (!dealerRewardConditionId && dealerPersonId) {
|
||||
calculationStore.setStatus('selectDealerBroker', ElementStatus.Default);
|
||||
} else {
|
||||
calculationStore.setValue('dealerBroker', null);
|
||||
calculationStore.setStatus(
|
||||
'selectDealerBroker',
|
||||
ElementStatus.Disabled,
|
||||
);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { dealerBrokerRewardCondition } = calculationStore.values;
|
||||
|
||||
@ -324,9 +324,6 @@ export default [
|
||||
return indAgent;
|
||||
},
|
||||
effect: indAgentId => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
if (!indAgentId) {
|
||||
calculationStore.setValue('indAgentRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
@ -340,7 +337,7 @@ export default [
|
||||
ElementStatus.Default,
|
||||
);
|
||||
|
||||
if (indAgentId)
|
||||
if (indAgentId && calculationProcess.process === Process.Default)
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
@ -388,9 +385,6 @@ export default [
|
||||
return calcDoubleAgent;
|
||||
},
|
||||
effect: doubleAgentId => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
if (!doubleAgentId) {
|
||||
calculationStore.setValue('calcDoubleAgentRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
@ -404,7 +398,7 @@ export default [
|
||||
ElementStatus.Default,
|
||||
);
|
||||
|
||||
if (doubleAgentId)
|
||||
if (doubleAgentId && calculationProcess.process === Process.Default)
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
@ -513,9 +507,6 @@ export default [
|
||||
return calcBroker;
|
||||
},
|
||||
effect: calcBrokerId => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
if (!calcBrokerId) {
|
||||
calculationStore.setValue('calcBrokerRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
@ -529,7 +520,7 @@ export default [
|
||||
ElementStatus.Default,
|
||||
);
|
||||
|
||||
if (calcBrokerId)
|
||||
if (calcBrokerId && calculationProcess.process === Process.Default)
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
@ -634,6 +625,7 @@ export default [
|
||||
},
|
||||
}),
|
||||
|
||||
//TODO: maybe refactor
|
||||
(calculationStore, calculationProcess) => ({
|
||||
expression: () => {
|
||||
const { dealerPerson } = calculationStore.values;
|
||||
@ -693,9 +685,6 @@ export default [
|
||||
return dealerBroker;
|
||||
},
|
||||
effect: dealerBrokerId => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
if (dealerBrokerId) {
|
||||
const dealerBroker = calculationStore.options.selectDealerBroker?.find(
|
||||
x => x.accountid === dealerBrokerId,
|
||||
@ -706,6 +695,66 @@ export default [
|
||||
ElementStatus.Default,
|
||||
);
|
||||
|
||||
if (calculationProcess.process === Process.Default)
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
$statecode: Int
|
||||
$currentDate: DateTime
|
||||
$evo_agent_accountid: Uuid
|
||||
) {
|
||||
evo_reward_condition: evo_reward_conditions(
|
||||
evo_agent_accountid: $evo_agent_accountid
|
||||
evo_datefrom_param: { lte: $currentDate }
|
||||
evo_dateto_param: { gte: $currentDate }
|
||||
statecode: $statecode
|
||||
) {
|
||||
evo_reward_conditionid
|
||||
evo_name
|
||||
evo_reward_summ
|
||||
evo_reduce_reward
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
evo_agent_accountid: dealerBrokerId,
|
||||
currentDate,
|
||||
statecode: 0,
|
||||
},
|
||||
toOptions: ['evo_reward_condition'],
|
||||
}).then(({ entities: { evo_reward_condition } }) => {
|
||||
if (evo_reward_condition && Array.isArray(evo_reward_condition))
|
||||
calculationStore.setOptions(
|
||||
'selectDealerBrokerRewardCondition',
|
||||
evo_reward_condition,
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
calculationStore.setValue('dealerBrokerRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
'selectDealerBrokerRewardCondition',
|
||||
ElementStatus.Disabled,
|
||||
);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
(calculationStore, calculationProcess) => ({
|
||||
expression: () => {
|
||||
const { dealerBroker, dealerPerson } = calculationStore.values;
|
||||
return [dealerBroker, dealerPerson];
|
||||
},
|
||||
effect: ([dealerBrokerId, dealerPersonId]) => {
|
||||
if (dealerPersonId && !dealerBrokerId) {
|
||||
calculationStore.setStatus(
|
||||
'selectDealerRewardCondition',
|
||||
ElementStatus.Default,
|
||||
);
|
||||
if (calculationProcess.process === Process.Default)
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
@ -727,7 +776,7 @@ export default [
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
evo_agent_accountid: dealerBrokerId,
|
||||
evo_agent_accountid: dealerPersonId,
|
||||
currentDate,
|
||||
statecode: 0,
|
||||
},
|
||||
@ -735,72 +784,10 @@ export default [
|
||||
}).then(({ entities: { evo_reward_condition } }) => {
|
||||
if (evo_reward_condition && Array.isArray(evo_reward_condition))
|
||||
calculationStore.setOptions(
|
||||
'selectDealerBrokerRewardCondition',
|
||||
'selectDealerRewardCondition',
|
||||
evo_reward_condition,
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
calculationStore.setValue('dealerBrokerRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
'selectDealerBrokerRewardCondition',
|
||||
ElementStatus.Disabled,
|
||||
);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
(calculationStore, calculationProcess) => ({
|
||||
expression: () => {
|
||||
const { dealerBroker, dealerPerson } = calculationStore.values;
|
||||
return [dealerBroker, dealerPerson];
|
||||
},
|
||||
effect: ([dealerBrokerId, dealerPersonId]) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
if (dealerPersonId && !dealerBrokerId) {
|
||||
calculationStore.setStatus(
|
||||
'selectDealerRewardCondition',
|
||||
ElementStatus.Default,
|
||||
);
|
||||
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query(
|
||||
$statecode: Int
|
||||
$currentDate: DateTime
|
||||
$evo_agent_accountid: Uuid
|
||||
) {
|
||||
evo_reward_condition: evo_reward_conditions(
|
||||
evo_agent_accountid: $evo_agent_accountid
|
||||
evo_datefrom_param: { lte: $currentDate }
|
||||
evo_dateto_param: { gte: $currentDate }
|
||||
statecode: $statecode
|
||||
) {
|
||||
evo_reward_conditionid
|
||||
evo_name
|
||||
evo_reward_summ
|
||||
evo_reduce_reward
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
evo_agent_accountid: dealerPersonId,
|
||||
currentDate,
|
||||
statecode: 0,
|
||||
},
|
||||
toOptions: ['evo_reward_condition'],
|
||||
}).then(({ entities: { evo_reward_condition } }) => {
|
||||
if (evo_reward_condition && Array.isArray(evo_reward_condition))
|
||||
calculationStore.setOptions(
|
||||
'selectDealerRewardCondition',
|
||||
evo_reward_condition,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
calculationStore.setValue('dealerRewardCondition', null);
|
||||
calculationStore.setStatus(
|
||||
@ -823,48 +810,43 @@ export default [
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
calculationStore.setStatus('selectModel', ElementStatus.Disabled);
|
||||
|
||||
calculationStore.setOptions('selectModel', []);
|
||||
calculationStore.setValue('model', null);
|
||||
|
||||
if (brandId) {
|
||||
const brand = calculationStore.options.selectBrand?.find(
|
||||
x => x.evo_brandid === brandId,
|
||||
);
|
||||
if (brand) {
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query($statecode: Int, $evo_brandid: Uuid) {
|
||||
evo_model: evo_models(
|
||||
statecode: $statecode
|
||||
evo_brandid: $evo_brandid
|
||||
) {
|
||||
evo_name
|
||||
evo_modelid
|
||||
evo_leasingobject_risk
|
||||
evo_importer_reward_perc
|
||||
evo_importer_reward_rub
|
||||
evo_impairment_groupid
|
||||
}
|
||||
CrmService.crmgqlquery({
|
||||
query: gql`
|
||||
query($statecode: Int, $evo_brandid: Uuid) {
|
||||
evo_model: evo_models(
|
||||
statecode: $statecode
|
||||
evo_brandid: $evo_brandid
|
||||
) {
|
||||
evo_name
|
||||
evo_modelid
|
||||
evo_leasingobject_risk
|
||||
evo_importer_reward_perc
|
||||
evo_importer_reward_rub
|
||||
evo_impairment_groupid
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
statecode: 0,
|
||||
evo_brandid: brandId,
|
||||
},
|
||||
toOptions: ['evo_model'],
|
||||
}).then(({ entities }) => {
|
||||
if (
|
||||
entities.evo_model &&
|
||||
Array.isArray(entities.evo_model) &&
|
||||
entities.evo_model.length > 0
|
||||
) {
|
||||
calculationStore.setStatus('selectModel', ElementStatus.Default);
|
||||
calculationStore.setOptions('selectModel', entities.evo_model);
|
||||
calculationStore.setValue('model', null);
|
||||
}
|
||||
});
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
statecode: 0,
|
||||
evo_brandid: brandId,
|
||||
},
|
||||
toOptions: ['evo_model'],
|
||||
}).then(({ entities }) => {
|
||||
if (
|
||||
entities.evo_model &&
|
||||
Array.isArray(entities.evo_model) &&
|
||||
entities.evo_model.length > 0
|
||||
) {
|
||||
calculationStore.setOptions('selectModel', entities.evo_model);
|
||||
calculationStore.setValue('model', null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
}
|
||||
},
|
||||
options: { fireImmediately: true },
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
import { ElementsNames } from './../../../../../core/types/Calculation/Store/elements';
|
||||
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
|
||||
const elementsNames: ElementsNames[] = [
|
||||
'selectModel',
|
||||
'selectConfiguration',
|
||||
'selectGPSModel',
|
||||
'selectTownRegistration',
|
||||
'selectDealerPerson',
|
||||
];
|
||||
|
||||
export default elementsNames.map(elementName => calculationStore => ({
|
||||
expression: () => {
|
||||
const { [elementName]: elementOptions } = calculationStore.options;
|
||||
return elementOptions?.length;
|
||||
},
|
||||
effect: length => {
|
||||
if (length === 0) {
|
||||
calculationStore.setStatus(elementName, ElementStatus.Disabled);
|
||||
} else {
|
||||
calculationStore.setStatus(elementName, ElementStatus.Default);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
})) as IReactionEffect[];
|
||||
Reference in New Issue
Block a user