process: add type ReactionsContext

This commit is contained in:
Chika 2022-11-03 12:13:09 +03:00
parent 21c97ece2b
commit 0569d45972
15 changed files with 59 additions and 86 deletions

View File

@ -46,7 +46,7 @@ function Home() {
useEffect(() => {
getData(apolloClient, store);
injectDefaultReactions(store, apolloClient, queryClient, trpcPureClient);
injectDefaultReactions({ store, apolloClient, queryClient, trpcClient: trpcPureClient });
}, []);
return (

View File

@ -1,8 +1,7 @@
import type { ApolloClient } from '@apollo/client';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
export default function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export default function validationReactions({ store }: ReactionsContext) {
const { $calculation, $tables } = store;
reaction(
() => {

View File

@ -1,9 +1,8 @@
/* eslint-disable implicit-arrow-linebreak */
/* eslint-disable unicorn/consistent-function-scoping */
/* eslint-disable @typescript-eslint/naming-convention */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import type { QueryClient, QueryFunctionContext } from '@tanstack/react-query';
import type { QueryFunctionContext } from '@tanstack/react-query';
import { calculateFinGAP } from 'api/core/query';
import type { RequestFinGAP } from 'api/core/types';
import type { Risk } from 'Components/Calculation/Form/Insurance/FinGAPTable/types';
@ -12,16 +11,12 @@ import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { comparer, reaction, toJS } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
import { flatten } from 'tools/object';
dayjs.extend(utc);
export default function commonReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient
) {
export default function commonReactions({ store, apolloClient, queryClient }: ReactionsContext) {
const { $calculation, $tables } = store;
// Расчет итоговой суммы ФинГАП и запись в таблицу страхования
reaction(

View File

@ -1,13 +1,7 @@
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 { ReactionsContext } from 'process/types';
export default function validationReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient
) {
export default function validationReactions({ store }: ReactionsContext) {
const { $tables } = store;
reaction(

View File

@ -9,20 +9,20 @@ import leasebackReactions from '../../supplier-agent/reactions/leaseback';
import * as supplierReactions from '../../supplier-agent/reactions/supplier';
import setInitialValuesReactions from '../set-values/reactions';
export default function injectDefaultReactions(store, apolloClient, queryClient, trpcClient) {
leadOpportunityReactions.common(store, apolloClient, queryClient);
leadOpportunityReactions.urls(store, apolloClient, queryClient);
paymentsReactions(store, apolloClient, queryClient);
calculateReactions.validation(store, apolloClient, queryClient);
supplierReactions.commonReactions(store, apolloClient, queryClient);
supplierReactions.validationReactions(store, apolloClient, queryClient);
agentsReactions.fillReactions(store, apolloClient, queryClient);
agentsReactions.commonReactions(store, apolloClient, queryClient);
agentsReactions.validationReactions(store, apolloClient, queryClient);
leasebackReactions(store, apolloClient, queryClient);
priceReactions.computed(store, apolloClient, queryClient);
fingapReactions.common(store, apolloClient, queryClient);
fingapReactions.validation(store, apolloClient, queryClient);
setInitialValuesReactions(store, apolloClient, queryClient);
loadKpReactions(store, apolloClient, queryClient, trpcClient);
export default function injectDefaultReactions(context) {
leadOpportunityReactions.common(context);
leadOpportunityReactions.urls(context);
paymentsReactions(context);
calculateReactions.validation(context);
supplierReactions.commonReactions(context);
supplierReactions.validationReactions(context);
agentsReactions.fillReactions(context);
agentsReactions.commonReactions(context);
agentsReactions.validationReactions(context);
leasebackReactions(context);
priceReactions.computed(context);
fingapReactions.common(context);
fingapReactions.validation(context);
setInitialValuesReactions(context);
loadKpReactions(context);
}

View File

@ -1,16 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import type { GetTransactionCurrenciesQuery } from 'graphql/crm.types';
import { when } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
export default function setInitialValuesReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient
) {
export default function setInitialValuesReactions({ store, apolloClient }: ReactionsContext) {
const QUERY_GET_TRANSACTION_CURRENCIES = gql`
query GetTransactionCurrencies {
transactioncurrencies {

View File

@ -1,13 +1,12 @@
/* eslint-disable implicit-arrow-linebreak */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
import { normalizeOptions } from 'tools/entity';
import { makeDisposable } from 'tools/mobx';
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**

View File

@ -1,10 +1,10 @@
import type { ApolloClient, DocumentNode } from '@apollo/client';
import type { DocumentNode } from '@apollo/client';
import { gql } from '@apollo/client';
import type { Elements } from 'Components/Calculation/config/map/values';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
export default function urlsReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export default function urlsReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**

View File

@ -1,16 +1,8 @@
import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import message from 'Elements/message';
import { reaction, toJS } from 'mobx';
import type RootStore from 'stores/root';
import type { TRPCPureClient } from 'trpc/types';
import { reaction } from 'mobx';
import type { ReactionsContext } from 'process/types';
export default function loadKpReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient,
trpcClient: TRPCPureClient
) {
export default function loadKpReactions({ store, trpcClient }: ReactionsContext) {
const { $calculation, $process } = store;
reaction(
@ -21,12 +13,11 @@ export default function loadKpReactions(
$process.add('LoadKP');
const quoteName = $calculation.element('selectQuote').getOption()?.label;
const { quote } = toJS($calculation.$values.values);
trpcClient.quote.getValues
.query({
values: {
quote,
quote: quoteId,
},
})
.then(({ values }) => {

View File

@ -1,12 +1,10 @@
/* eslint-disable function-paren-newline */
/* eslint-disable implicit-arrow-linebreak */
import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import { selectHighSeasonStart, selectSeasonType } from 'config/default-options';
import { comparer, reaction, toJS } from 'mobx';
import type { ReactionsContext } from 'process/types';
import { shift } from 'radash';
import type { CalculationOptions } from 'stores/calculation/options/types';
import type RootStore from 'stores/root';
import type { Row } from 'stores/tables/payments/types';
import ValidationHelper from 'stores/validation/helper';
import { difference } from 'tools/array';
@ -15,11 +13,7 @@ import * as seasonsConstants from './lib/seasons-constants';
import * as seasonsTools from './lib/seasons-tools';
import validatePaymentsTable from './validation';
export default function paymentsReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient
) {
export default function paymentsReactions({ store }: ReactionsContext) {
const { $calculation, $tables, $process } = store;
reaction(

View File

@ -1,15 +1,14 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { autorun } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
dayjs.extend(utc);
export default function computedReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export default function computedReactions({ store, apolloClient }: ReactionsContext) {
const QUERY_GET_EVO_CURRENCY_CHANGES = gql`
query GetCurrencyChanges($currentDate: DateTime) {
evo_currencychanges(statecode: 0, evo_coursedate_param: { eq: $currentDate }) {

View File

@ -1,18 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
import { makeDisposable } from 'tools/mobx';
import * as createReactions from '../lib/create-reactions';
import * as fillAgentsFromLead from '../lib/fill-agents-from-lead';
dayjs.extend(utc);
export function fillReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export function fillReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**
@ -93,7 +92,7 @@ export function fillReactions(store: RootStore, apolloClient: ApolloClient<objec
});
}
export function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
const QUERY_GET_REWARD_WITHOUT_OTHER_AGENT = gql`
@ -480,7 +479,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
);
}
export function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export function validationReactions({ store, apolloClient }: ReactionsContext) {
createReactions.validateAgentRewardSumm(store, apolloClient, {
rewardConditionField: 'selectDealerRewardCondition',
rewardSummField: 'tbxDealerRewardSumm',

View File

@ -1,10 +1,9 @@
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type RootStore from 'stores/root';
import type { ReactionsContext } from 'process/types';
export default function leasebackReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export default function leasebackReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $tables } = store;
/**
* Дополнить реакцию на изменение поля Салон приобретения selectDealer:

View File

@ -1,19 +1,18 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import type { ReactionsContext } from 'process/types';
import { sift } from 'radash';
import type RootStore from 'stores/root';
import { normalizeOptions } from 'tools/entity';
import * as createReactions from '../lib/create-reactions';
import * as query from '../lib/query';
dayjs.extend(utc);
export function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
export function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**
@ -170,4 +169,4 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
);
}
export function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {}
export function validationReactions({ store, apolloClient }: ReactionsContext) {}

11
process/types.ts Normal file
View File

@ -0,0 +1,11 @@
import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import type RootStore from 'stores/root';
import type { TRPCPureClient } from 'trpc/types';
export type ReactionsContext = {
store: RootStore;
apolloClient: ApolloClient<object>;
queryClient: QueryClient;
trpcClient: TRPCPureClient;
};