diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index eb0535c..773ed68 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -1,3 +1,4 @@ +import { getValueName } from 'client/Containers/Calculation/lib/elements/tools'; import { pipe } from 'core/tools/func'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { @@ -11,6 +12,7 @@ import { validate, ValidationCondition, } from 'core/validation/validate'; +import { isNil } from 'lodash'; const customConditions: TElements = { selectLeaseObjectCategory: calculationStore => { @@ -117,7 +119,32 @@ const elementsConditions = (Object.keys( {}, ); -const conditions = Object.assign({}, customConditions, elementsConditions); +const entityElementsConditions = ([ + 'selectIndAgentRewardCondition', + 'selectCalcBrokerRewardCondition', + 'selectFinDepartmentRewardCondtion', +] as ElementsNames[]).reduce( + (ac: TElements, elementName) => { + const valueName = getValueName(elementName); + ac[elementName] = (calculationStore, elementName) => { + if (isNil(calculationStore.getValue(valueName))) { + return { isValid: true }; + } + return { + isValid: calculationStore.getOption(elementName) !== undefined, + }; + }; + return ac; + }, + {}, +); + +const conditions = Object.assign( + {}, + customConditions, + elementsConditions, + entityElementsConditions, +); export default function (this: ICalculationStore) { const validationResult = validate(this, conditions);