From 0569d45972025c9f8350473d4c36375a837e670e Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 3 Nov 2022 12:13:09 +0300 Subject: [PATCH] process: add type ReactionsContext --- pages/index.jsx | 2 +- process/calculate/reactions/validation.ts | 5 ++- process/fingap/reactions/common.ts | 11 ++----- process/fingap/reactions/validation.ts | 10 ++---- process/init/inject-reactions/default.js | 32 +++++++++---------- process/init/set-values/reactions.ts | 10 ++---- process/lead-opportunity/reactions/common.ts | 5 ++- process/lead-opportunity/reactions/urls.ts | 6 ++-- process/load-kp/reactions.ts | 17 +++------- process/payments/reactions.ts | 10 ++---- process/price/reactions/computed.ts | 5 ++- process/supplier-agent/reactions/agents.ts | 9 +++--- process/supplier-agent/reactions/leaseback.ts | 5 ++- process/supplier-agent/reactions/supplier.ts | 7 ++-- process/types.ts | 11 +++++++ 15 files changed, 59 insertions(+), 86 deletions(-) create mode 100644 process/types.ts diff --git a/pages/index.jsx b/pages/index.jsx index 7101151..837a4af 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -46,7 +46,7 @@ function Home() { useEffect(() => { getData(apolloClient, store); - injectDefaultReactions(store, apolloClient, queryClient, trpcPureClient); + injectDefaultReactions({ store, apolloClient, queryClient, trpcClient: trpcPureClient }); }, []); return ( diff --git a/process/calculate/reactions/validation.ts b/process/calculate/reactions/validation.ts index 76c55f3..72b4f10 100644 --- a/process/calculate/reactions/validation.ts +++ b/process/calculate/reactions/validation.ts @@ -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) { +export default function validationReactions({ store }: ReactionsContext) { const { $calculation, $tables } = store; reaction( () => { diff --git a/process/fingap/reactions/common.ts b/process/fingap/reactions/common.ts index 311df0e..2a4a0e3 100644 --- a/process/fingap/reactions/common.ts +++ b/process/fingap/reactions/common.ts @@ -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, - queryClient: QueryClient -) { +export default function commonReactions({ store, apolloClient, queryClient }: ReactionsContext) { const { $calculation, $tables } = store; // Расчет итоговой суммы ФинГАП и запись в таблицу страхования reaction( diff --git a/process/fingap/reactions/validation.ts b/process/fingap/reactions/validation.ts index 64eca5a..aa0675e 100644 --- a/process/fingap/reactions/validation.ts +++ b/process/fingap/reactions/validation.ts @@ -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, - queryClient: QueryClient -) { +export default function validationReactions({ store }: ReactionsContext) { const { $tables } = store; reaction( diff --git a/process/init/inject-reactions/default.js b/process/init/inject-reactions/default.js index 5de44a9..f7c32ca 100644 --- a/process/init/inject-reactions/default.js +++ b/process/init/inject-reactions/default.js @@ -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); } diff --git a/process/init/set-values/reactions.ts b/process/init/set-values/reactions.ts index 11c25c7..7422bce 100644 --- a/process/init/set-values/reactions.ts +++ b/process/init/set-values/reactions.ts @@ -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, - queryClient: QueryClient -) { +export default function setInitialValuesReactions({ store, apolloClient }: ReactionsContext) { const QUERY_GET_TRANSACTION_CURRENCIES = gql` query GetTransactionCurrencies { transactioncurrencies { diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index ab8df2d..4cef9a3 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -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) { +export default function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation, $process } = store; /** diff --git a/process/lead-opportunity/reactions/urls.ts b/process/lead-opportunity/reactions/urls.ts index 477f719..694c974 100644 --- a/process/lead-opportunity/reactions/urls.ts +++ b/process/lead-opportunity/reactions/urls.ts @@ -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) { +export default function urlsReactions({ store, apolloClient }: ReactionsContext) { const { $calculation } = store; /** diff --git a/process/load-kp/reactions.ts b/process/load-kp/reactions.ts index 2f64454..40f60b4 100644 --- a/process/load-kp/reactions.ts +++ b/process/load-kp/reactions.ts @@ -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, - 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 }) => { diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index e5dca45..cd18b75 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -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, - queryClient: QueryClient -) { +export default function paymentsReactions({ store }: ReactionsContext) { const { $calculation, $tables, $process } = store; reaction( diff --git a/process/price/reactions/computed.ts b/process/price/reactions/computed.ts index c2c20be..159c22d 100644 --- a/process/price/reactions/computed.ts +++ b/process/price/reactions/computed.ts @@ -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) { +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 }) { diff --git a/process/supplier-agent/reactions/agents.ts b/process/supplier-agent/reactions/agents.ts index abfd843..9f01283 100644 --- a/process/supplier-agent/reactions/agents.ts +++ b/process/supplier-agent/reactions/agents.ts @@ -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) { +export function fillReactions({ store, apolloClient }: ReactionsContext) { const { $calculation, $process } = store; /** @@ -93,7 +92,7 @@ export function fillReactions(store: RootStore, apolloClient: ApolloClient) { +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) { +export function validationReactions({ store, apolloClient }: ReactionsContext) { createReactions.validateAgentRewardSumm(store, apolloClient, { rewardConditionField: 'selectDealerRewardCondition', rewardSummField: 'tbxDealerRewardSumm', diff --git a/process/supplier-agent/reactions/leaseback.ts b/process/supplier-agent/reactions/leaseback.ts index bb9e9e0..fb644f9 100644 --- a/process/supplier-agent/reactions/leaseback.ts +++ b/process/supplier-agent/reactions/leaseback.ts @@ -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) { +export default function leasebackReactions({ store, apolloClient }: ReactionsContext) { const { $calculation, $tables } = store; /** * Дополнить реакцию на изменение поля Салон приобретения selectDealer: diff --git a/process/supplier-agent/reactions/supplier.ts b/process/supplier-agent/reactions/supplier.ts index 8df291c..a8b09d8 100644 --- a/process/supplier-agent/reactions/supplier.ts +++ b/process/supplier-agent/reactions/supplier.ts @@ -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) { +export function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation, $process } = store; /** @@ -170,4 +169,4 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient) {} +export function validationReactions({ store, apolloClient }: ReactionsContext) {} diff --git a/process/types.ts b/process/types.ts new file mode 100644 index 0000000..26c22e9 --- /dev/null +++ b/process/types.ts @@ -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; + queryClient: QueryClient; + trpcClient: TRPCPureClient; +};