From 6172833fdbbbf614ddc9692ee4ab5710b9c37983 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 2 Feb 2023 13:26:49 +0300 Subject: [PATCH] process/price: add common reactions --- apps/web/constants/values.js | 1 + .../process/init/inject-reactions/default.js | 1 + apps/web/process/price/reactions/common.ts | 50 +++++++++++++++++++ apps/web/process/price/reactions/index.js | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 apps/web/process/price/reactions/common.ts diff --git a/apps/web/constants/values.js b/apps/web/constants/values.js index 4335663..5af532c 100644 --- a/apps/web/constants/values.js +++ b/apps/web/constants/values.js @@ -4,3 +4,4 @@ export const MIN_INSURANCE = 3000; export const RATE = 7.75; export const MAX_LEASING_PERIOD = 60; +export const MIN_LASTPAYMENT_NSIB = 3500; diff --git a/apps/web/process/init/inject-reactions/default.js b/apps/web/process/init/inject-reactions/default.js index 14bb161..dcdf9b6 100644 --- a/apps/web/process/init/inject-reactions/default.js +++ b/apps/web/process/init/inject-reactions/default.js @@ -25,6 +25,7 @@ export default function injectDefaultReactions(context) { agentsReactions.validationReactions(context); leasebackReactions(context); priceReactions.computed(context); + priceReactions.common(context); fingapReactions.common(context); fingapReactions.validation(context); setInitialValuesReactions(context); diff --git a/apps/web/process/price/reactions/common.ts b/apps/web/process/price/reactions/common.ts new file mode 100644 index 0000000..4de89e7 --- /dev/null +++ b/apps/web/process/price/reactions/common.ts @@ -0,0 +1,50 @@ +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} руб. не может быть при наличии НСИБ, укажите большее значение`, + }); + } + ); +} diff --git a/apps/web/process/price/reactions/index.js b/apps/web/process/price/reactions/index.js index d5e79ce..ddb1f56 100644 --- a/apps/web/process/price/reactions/index.js +++ b/apps/web/process/price/reactions/index.js @@ -1,2 +1,2 @@ -/* eslint-disable import/prefer-default-export */ +export { default as common } from './common'; export { default as computed } from './computed';