diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index aa22b1e..14ad190 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -1,15 +1,17 @@ import type { ApolloClient } from '@apollo/client'; -import { reaction } from 'mobx'; +import { reaction, toJS } from 'mobx'; import type RootStore from 'stores/root'; export default function paymentsReactions(store: RootStore, apolloClient: ApolloClient) { - const { $calculation } = store; + const { $calculation, $tables } = store; + /** + * При изменении срока лизинга регулируем длину таблицы платежей + */ reaction( () => $calculation.$values.getValue('leasingPeriod'), (leasingPeriod) => { if (leasingPeriod) { - const { $tables } = store; $tables.payments.setValues( Array.from( { @@ -24,4 +26,21 @@ export default function paymentsReactions(store: RootStore, apolloClient: Apollo fireImmediately: true, } ); + + /** + * Проверяем платежи на 0 + */ + const errorText = 'Значения не должны быть равны 0'; + let removeError: () => void; + + reaction( + () => toJS($tables.payments.values), + (values) => { + if (values.includes(0)) { + removeError = $tables.payments.validation.addError(errorText); + } else { + removeError(); + } + } + ); } diff --git a/stores/tables/payments/index.ts b/stores/tables/payments/index.ts index ca16ef2..f6b8898 100644 --- a/stores/tables/payments/index.ts +++ b/stores/tables/payments/index.ts @@ -1,6 +1,6 @@ import type { Status } from 'Elements/types'; import type { IObservableArray } from 'mobx'; -import { makeAutoObservable, observable, reaction, toJS } from 'mobx'; +import { makeAutoObservable, observable, reaction } from 'mobx'; import type RootStore from 'stores/root'; import Validation from '../validation'; @@ -35,23 +35,6 @@ export default class PaymentsTable { this.statuses.length = length; } ); - - /** - * Проверяем платежи на 0 - */ - const errorText = 'Значения не должны быть равны 0'; - let removeError: () => void; - - reaction( - () => toJS(this.values), - (values) => { - if (values.includes(0)) { - removeError = this.validation.addError(errorText); - } else { - removeError(); - } - } - ); } getValue(index: number) {