fix validation

This commit is contained in:
vchikalkin 2021-04-05 17:25:29 +03:00 committed by Chika
parent b70e417faf
commit f7877f6892
2 changed files with 37 additions and 19 deletions

View File

@ -30,18 +30,17 @@ const elementsValidations: TElements<any> = {
// selectRate: VALIDATIONS.IS_NULL,
selectRegistration: VALIDATIONS.IS_NULL,
selectLeaseObjectCategory: VALIDATIONS.IS_NULL,
tbxLeasingPeriod: valueName => CalculationStore.getValue(valueName) < 7,
selectSeasonType: valueName =>
CalculationStore.getValue('graphType') === 100000003 &&
VALIDATIONS.IS_NULL(valueName),
selectHighSeasonStart: valueName =>
CalculationStore.getValue('graphType') === 100000003 &&
VALIDATIONS.IS_NULL(valueName),
// selectSeasonType: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
// selectHighSeasonStart: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
tbxLeaseObjectPrice: VALIDATIONS.LESS_OR_EQUALS_ZERO,
tbxLastPaymentPerc: VALIDATIONS.IS_NULL,
tbxLastPaymentRub: VALIDATIONS.IS_NULL,
tbxFirstPaymentPerc: VALIDATIONS.IS_NULL,
tbxFirstPaymentRub: VALIDATIONS.IS_NULL,
// tbxLastPaymentPerc: VALIDATIONS.IS_NULL,
// tbxLastPaymentRub: VALIDATIONS.IS_NULL,
// tbxFirstPaymentPerc: VALIDATIONS.IS_NULL,
// tbxFirstPaymentRub: VALIDATIONS.IS_NULL,
tbxLeaseObjectCount: VALIDATIONS.LESS_OR_EQUALS_ZERO,
selectQuote: valueName =>
CalculationStore.getValue('recalcWithRevision') === true &&
@ -52,19 +51,11 @@ const validateElement = (elementName, condition) => {
if (condition) {
CalculationStore.setValidation(elementName, false);
} else {
//TODO: antidote in reactions
CalculationStore.setValidation(elementName, true);
}
};
const validateElements = () => {
if (
Object.keys(CalculationStore.validations).some(
x => CalculationStore.validations[x] === false,
)
) {
return;
}
Object.keys(elementsValidations).forEach(elementName => {
validateElement(
elementName,

View File

@ -1768,6 +1768,33 @@ const reactionEffects: IReactionEffect[] = [
fireImmediately: true,
},
}),
// TODO: revert to validator
calculationStore => ({
expression: () => {
const { graphType, seasonType } = calculationStore.values;
return [graphType, seasonType];
},
effect: ([graphType, seasonType]) => {
calculationStore.setValidation(
'selectSeasonType',
!(graphType === 100000003 && seasonType === null),
);
},
}),
calculationStore => ({
expression: () => {
const { graphType, highSeasonStart } = calculationStore.values;
return [graphType, highSeasonStart];
},
effect: ([graphType, highSeasonStart]) => {
calculationStore.setValidation(
'selectHighSeasonStart',
!(graphType === 100000003 && highSeasonStart === null),
);
},
}),
];
export default reactionEffects;