65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import validatePaymentsTable from '../lib/validation';
|
||
import { MIN_LASTPAYMENT_NSIB } from '@/constants/values';
|
||
import type { ReactionsContext } from '@/process/types';
|
||
import ValidationHelper from '@/stores/validation/helper';
|
||
import { comparer, reaction, toJS } from 'mobx';
|
||
|
||
export default function reactions({ store }: ReactionsContext) {
|
||
const { $calculation, $tables } = store;
|
||
|
||
const validationHelper = new ValidationHelper();
|
||
|
||
reaction(
|
||
() => {
|
||
const payments = toJS($tables.payments.values);
|
||
const graphType = $calculation.element('radioGraphType').getValue();
|
||
const seasonType = $calculation.element('selectSeasonType').getValue();
|
||
const highSeasonStart = $calculation.element('selectHighSeasonStart').getValue();
|
||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||
|
||
return {
|
||
graphType,
|
||
highSeasonStart,
|
||
leasingPeriod,
|
||
payments,
|
||
seasonType,
|
||
};
|
||
},
|
||
() => {
|
||
validationHelper.removeErrors();
|
||
|
||
const errorText = validatePaymentsTable(store);
|
||
|
||
if (errorText) {
|
||
$tables.payments.validate({
|
||
helper: validationHelper,
|
||
invalid: errorText !== null,
|
||
message: errorText,
|
||
});
|
||
}
|
||
},
|
||
{
|
||
delay: 50,
|
||
equals: comparer.structural,
|
||
}
|
||
);
|
||
|
||
reaction(
|
||
() => {
|
||
const lastPaymentRub = $calculation.element('tbxLastPaymentRub').getValue();
|
||
const insNSIB = $calculation.element('selectInsNSIB').getValue();
|
||
|
||
return {
|
||
insNSIB,
|
||
lastPaymentRub,
|
||
};
|
||
},
|
||
({ lastPaymentRub, insNSIB }) => {
|
||
$calculation.element('tbxLastPaymentRub').validate({
|
||
invalid: Boolean(insNSIB) && lastPaymentRub < MIN_LASTPAYMENT_NSIB,
|
||
message: `Последний платеж меньше ${MIN_LASTPAYMENT_NSIB} руб. не может быть при наличии НСИБ, укажите большее значение`,
|
||
});
|
||
}
|
||
);
|
||
}
|