2023-02-03 08:30:24 +03:00

51 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { MIN_LASTPAYMENT_NSIB } from 'constants/values';
import { reaction } from 'mobx';
import type { ReactionsContext } from 'process/types';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(
() => $calculation.element('radioLastPaymentRule').getValue(),
(lastPaymentRule) => {
switch (lastPaymentRule) {
case 100_000_000: {
$calculation.element('tbxLastPaymentPerc').block();
$calculation.element('tbxLastPaymentRub').unblock();
break;
}
case 100_000_001: {
$calculation.element('tbxLastPaymentPerc').unblock();
$calculation.element('tbxLastPaymentRub').block();
break;
}
default: {
$calculation.element('tbxLastPaymentPerc').block();
$calculation.element('tbxLastPaymentRub').block();
}
}
},
{
fireImmediately: true,
}
);
reaction(
() => {
const lastPaymentRub = $calculation.element('tbxLastPaymentRub').getValue();
const insNSIB = $calculation.element('selectInsNSIB').getValue();
return {
lastPaymentRub,
insNSIB,
};
},
({ lastPaymentRub, insNSIB }) => {
$calculation.element('tbxLastPaymentRub').validate({
invalid: !!insNSIB && lastPaymentRub < MIN_LASTPAYMENT_NSIB,
message: `Последний платеж меньше ${MIN_LASTPAYMENT_NSIB} руб. не может быть при наличии НСИБ, укажите большее значение`,
});
}
);
}