2022-10-26 19:07:46 +03:00

37 lines
1.1 KiB
TypeScript

import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { RemoveError } from 'stores/validation/types';
export default function validationReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient
) {
const { $tables } = store;
const errorText = 'Неверно заполнены платежи';
let removeError: RemoveError | undefined;
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 if (removeError) removeError();
},
{
fireImmediately: true,
}
);
}