42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import type { ProcessContext } from '@/process/types';
|
|
import ValidationHelper from '@/stores/validation/helper';
|
|
import { reaction } from 'mobx';
|
|
import { uid } from 'radash';
|
|
|
|
const key = uid(7);
|
|
|
|
export default function reactions({ store }: ProcessContext) {
|
|
const { $tables } = store;
|
|
|
|
const helper = new ValidationHelper();
|
|
reaction(
|
|
() => {
|
|
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
|
const finGAPInsuranceCompany = $tables.insurance.row('fingap').getValue('insuranceCompany');
|
|
|
|
return {
|
|
finGAPInsuranceCompany,
|
|
hasPaymentsErrors,
|
|
};
|
|
},
|
|
({ hasPaymentsErrors, finGAPInsuranceCompany }) => {
|
|
if (finGAPInsuranceCompany !== null && hasPaymentsErrors) {
|
|
const removeError = $tables.fingap.setError({
|
|
key,
|
|
message: 'Неверно заполнены платежи',
|
|
});
|
|
helper.add(removeError);
|
|
} else {
|
|
helper.removeErrors();
|
|
}
|
|
|
|
if (hasPaymentsErrors) {
|
|
$tables.fingap.clear();
|
|
}
|
|
},
|
|
{
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
}
|