payments: move validation reactions to process

This commit is contained in:
Chika 2022-07-09 16:17:34 +03:00
parent 1df138c51f
commit 7a10d72408
2 changed files with 23 additions and 21 deletions

View File

@ -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<object>) {
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();
}
}
);
}

View File

@ -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) {