30 lines
1004 B
TypeScript
30 lines
1004 B
TypeScript
import type { ApolloClient } from '@apollo/client';
|
|
import { reaction } from 'mobx';
|
|
import type RootStore from 'stores/root';
|
|
|
|
export default function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
|
const { $calculation, $tables } = store;
|
|
reaction(
|
|
() => {
|
|
const hasElementsErrors = $calculation.$validation.hasErrors;
|
|
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
|
const hasInsuranceErrors = $tables.insurance.validation.hasErrors;
|
|
const hasFingapErrors = $tables.fingap.validation.hasErrors;
|
|
|
|
return hasElementsErrors || hasPaymentsErrors || hasInsuranceErrors || hasFingapErrors;
|
|
},
|
|
(hasErrors) => {
|
|
if (hasErrors) {
|
|
$calculation.blockElement('btnCalculate');
|
|
$calculation.blockElement('btnCreateKP');
|
|
} else {
|
|
$calculation.unblockElement('btnCalculate');
|
|
$calculation.unblockElement('btnCreateKP');
|
|
}
|
|
},
|
|
{
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
}
|