40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import helper from '../lib/helper';
|
|
import type { ProcessContext } from '@/process/types';
|
|
import { reaction } from 'mobx';
|
|
import { formatter } from 'tools';
|
|
|
|
export default function reactions({ store, apolloClient }: ProcessContext) {
|
|
const { $calculation } = store;
|
|
|
|
reaction(
|
|
() => $calculation.element('radioCalcType').getValue(),
|
|
(calcType) => {
|
|
switch (calcType) {
|
|
case 100_000_001: {
|
|
$calculation.element('tbxIRR_Perc').block();
|
|
$calculation.element('tbxTotalPayments').unblock();
|
|
break;
|
|
}
|
|
case 100_000_000:
|
|
default: {
|
|
$calculation.element('tbxIRR_Perc').unblock();
|
|
$calculation.element('tbxTotalPayments').block();
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
const { getIrr } = helper({ apolloClient });
|
|
reaction(
|
|
() => $calculation.$values.getValues(['product', 'tarif', 'bonusCoefficient']),
|
|
async (values) => {
|
|
const { min, max } = await getIrr(values);
|
|
|
|
$calculation.element('labelIrrInfo').setValue(`${formatter(min)}% - ${formatter(max)}%`);
|
|
}
|
|
);
|
|
}
|