38 lines
1022 B
TypeScript
38 lines
1022 B
TypeScript
import type { ApolloClient } from '@apollo/client';
|
|
import type { QueryClient } from '@tanstack/react-query';
|
|
import { reaction } from 'mobx';
|
|
import type RootStore from 'stores/root';
|
|
|
|
export default function validationReactions(
|
|
store: RootStore,
|
|
apolloClient: ApolloClient<object>,
|
|
queryClient: QueryClient
|
|
) {
|
|
const { $tables } = store;
|
|
|
|
const errorText = 'Неверно заполнены платежи';
|
|
let removeError: () => void;
|
|
|
|
reaction(
|
|
() => {
|
|
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
|
const finGAPInsuranceCompany = $tables.insurance.getRowValue('fingap', 'insuranceCompany');
|
|
|
|
return {
|
|
hasPaymentsErrors,
|
|
finGAPInsuranceCompany,
|
|
};
|
|
},
|
|
({ hasPaymentsErrors, finGAPInsuranceCompany }) => {
|
|
if (finGAPInsuranceCompany && hasPaymentsErrors) {
|
|
removeError = $tables.fingap.validation.addError(errorText);
|
|
} else {
|
|
removeError();
|
|
}
|
|
},
|
|
{
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
}
|