organize exports: pt1

This commit is contained in:
vchikalkin 2023-02-17 19:53:39 +03:00
parent 0a4927cf29
commit 3556760714
35 changed files with 139 additions and 134 deletions

View File

@ -9,7 +9,7 @@ import { reaction } from 'mobx';
dayjs.extend(utc);
export default function commonReactions(context: ReactionsContext) {
export default function reactions(context: ReactionsContext) {
const { store, apolloClient } = context;
const { $calculation, $process } = store;
const { getCoefficient } = helper(context);

View File

@ -4,7 +4,7 @@ import type { ReactionsContext } from '@/process/types';
import { reaction } from 'mobx';
import { formatter } from 'tools';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(

View File

@ -13,7 +13,7 @@ function hasInvalidValueOrOptions(value: unknown, options: Array<BaseOption<unkn
return (value && !options?.length) || !options.some((x) => x.value === value);
}
export default function validationReactions({ store }: ReactionsContext) {
export default function reactions({ store }: ReactionsContext) {
const { $calculation, $tables } = store;
reaction(

View File

@ -11,7 +11,7 @@ import { normalizeOptions } from 'tools';
dayjs.extend(utc);
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(

View File

@ -3,7 +3,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import type { ReactionsContext } from '@/process/types';
import { reaction } from 'mobx';
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**
* На изменение поля Процет убывания платежей tbxParmentsDecreasePercent необходимо заложить проверку:

View File

@ -1,7 +1,7 @@
import type { ReactionsContext } from '../types';
import { reaction } from 'mobx';
export default function commonReactions({ store }: ReactionsContext) {
export function common({ store }: ReactionsContext) {
const { $calculation } = store;
reaction(

View File

@ -14,7 +14,7 @@ import { flatten } from 'tools/object';
dayjs.extend(utc);
export default function commonReactions({ store, apolloClient, queryClient }: ReactionsContext) {
export default function reactions({ store, apolloClient, queryClient }: ReactionsContext) {
const { $calculation, $tables } = store;
// Расчет итоговой суммы ФинГАП и запись в таблицу страхования
reaction(

View File

@ -1,7 +1,7 @@
import type { ReactionsContext } from '@/process/types';
import { reaction } from 'mobx';
export default function validationReactions({ store }: ReactionsContext) {
export default function reactions({ store }: ReactionsContext) {
const { $tables } = store;
reaction(

View File

@ -1,51 +1,42 @@
import * as bonusesReactions from '../../bonuses/reactions';
import * as calculateReactions from '../../calculate/reactions';
import * as configurator from '../../configurator/reactions';
import createKPReactions from '../../create-kp/reactions';
import * as createKPReactions from '../../create-kp/reactions';
import * as fingapReactions from '../../fingap/reactions';
import * as leadOpportunityReactions from '../../lead-opportunity/reactions';
import * as leasingObject from '../../leasing-object/reactions';
import * as leasingWithoutKaskoReactions from '../../leasing-without-kasko/reactions';
import loadKpReactions from '../../load-kp/reactions';
import * as paymentsReactions from '../../payments/reactions';
import * as loadKP from '../../load-kp/reactions';
import * as priceReactions from '../../price/reactions';
import * as subsidyReactions from '../../subsidy/reactions';
import subsidyImportProgram from '../../subsidy-import-program/reactions';
import * as agentsReactions from '../../supplier-agent/reactions/agents';
import leasebackReactions from '../../supplier-agent/reactions/leaseback';
import * as supplierReactions from '../../supplier-agent/reactions/supplier';
import * as subsidyImportProgram from '../../subsidy-import-program/reactions';
import * as agentsReactions from '../../supplier-agent/reactions';
import * as usedPl from '../../used-pl/reactions';
export default function injectDefaultReactions(context) {
leadOpportunityReactions.common(context);
leadOpportunityReactions.urls(context);
paymentsReactions.commonReactions(context);
paymentsReactions.validationReactions(context);
loadKP.common(context);
calculateReactions.validation(context);
calculateReactions.common(context);
supplierReactions.commonReactions(context);
supplierReactions.validationReactions(context);
agentsReactions.fillReactions(context);
agentsReactions.commonReactions(context);
agentsReactions.validationReactions(context);
leasebackReactions(context);
agentsReactions.common(context);
agentsReactions.validation(context);
priceReactions.computed(context);
priceReactions.common(context);
priceReactions.validation(context);
fingapReactions.common(context);
fingapReactions.validation(context);
loadKpReactions(context);
loadKP.common(context);
leasingWithoutKaskoReactions.common(context);
subsidyReactions.computedReactions(context);
subsidyReactions.commonReactions(context);
subsidyReactions.common(context);
leasingObject.common(context);
leasingObject.validation(context);
configurator.filters(context);
configurator.values(context);
configurator.validation(context);
createKPReactions(context);
createKPReactions.common(context);
bonusesReactions.common(context);
bonusesReactions.validation(context);
usedPl.default(context);
subsidyImportProgram(context);
usedPl.common(context);
subsidyImportProgram.common(context);
}

View File

@ -4,7 +4,7 @@ import { reaction } from 'mobx';
import { normalizeOptions } from 'tools/entity';
import { makeDisposable } from 'tools/mobx';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**

View File

@ -5,7 +5,7 @@ import type { DocumentNode } from '@apollo/client';
import { gql } from '@apollo/client';
import { reaction } from 'mobx';
export default function urlsReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**

View File

@ -5,7 +5,7 @@ import { reaction } from 'mobx';
import { intersects } from 'radash';
import { normalizeOptions } from 'tools';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(

View File

@ -4,7 +4,7 @@ import type { ReactionsContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { autorun, reaction } from 'mobx';
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**

View File

@ -42,7 +42,7 @@ const QUERY_GET_LEASING_WITHOUT_KASKO_OPTIONS = gql`
}
`;
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation, $tables } = store;
reaction(

View File

@ -1 +0,0 @@
export { default as common } from './common';

View File

@ -5,7 +5,7 @@ import message from 'ui/elements/message';
const key = 'KP_LOADING_INFO';
export default function loadKpReactions({ store, trpcClient }: ReactionsContext) {
export function common({ store, trpcClient }: ReactionsContext) {
const { $calculation, $process, $tables } = store;
reaction(

View File

@ -1,4 +1,4 @@
import { SEASONS_PERIOD_NUMBER, SEASONS_PERIODS } from './lib/seasons-constants';
import { SEASONS_PERIOD_NUMBER, SEASONS_PERIODS } from './seasons-constants';
import { MIN_PAYMENT } from '@/constants/values';
import type RootStore from '@/stores/root';
import { counting, max, min, shift, sort } from 'radash';

View File

@ -1,11 +1,9 @@
import * as seasonsConstants from './lib/seasons-constants';
import * as seasonsTools from './lib/seasons-tools';
import validatePaymentsTable from './validation';
import * as seasonsConstants from '../lib/seasons-constants';
import * as seasonsTools from '../lib/seasons-tools';
import { selectHighSeasonStart } from '@/config/default-options';
import { MIN_LASTPAYMENT_NSIB, MIN_PAYMENT } from '@/constants/values';
import { MIN_PAYMENT } from '@/constants/values';
import type { ReactionsContext } from '@/process/types';
import type { Row } from '@/stores/tables/payments/types';
import ValidationHelper from '@/stores/validation/helper';
import { comparer, reaction, toJS } from 'mobx';
import { shift } from 'radash';
import { difference } from 'tools/array';
@ -22,7 +20,7 @@ const {
const { DEFAULT_SEASONS_VALUES, FORBIDDEN_HIGH_SEASON_START, SEASONS_PERIOD_NUMBER } =
seasonsConstants;
export function commonReactions({ store }: ReactionsContext) {
export default function reactions({ store }: ReactionsContext) {
const { $calculation, $tables, $process } = store;
reaction(
@ -542,62 +540,3 @@ export function commonReactions({ store }: ReactionsContext) {
}
);
}
export function validationReactions({ store }: ReactionsContext) {
const { $calculation, $tables } = store;
const validationHelper = new ValidationHelper();
reaction(
() => {
const payments = toJS($tables.payments.values);
const graphType = $calculation.element('radioGraphType').getValue();
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStart = $calculation.element('selectHighSeasonStart').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
graphType,
highSeasonStart,
leasingPeriod,
payments,
seasonType,
};
},
() => {
validationHelper.removeErrors();
const errorText = validatePaymentsTable(store);
if (errorText) {
$tables.payments.validate({
helper: validationHelper,
invalid: errorText !== null,
message: errorText,
});
}
},
{
delay: 50,
equals: comparer.structural,
}
);
reaction(
() => {
const lastPaymentRub = $calculation.element('tbxLastPaymentRub').getValue();
const insNSIB = $calculation.element('selectInsNSIB').getValue();
return {
insNSIB,
lastPaymentRub,
};
},
({ lastPaymentRub, insNSIB }) => {
$calculation.element('tbxLastPaymentRub').validate({
invalid: Boolean(insNSIB) && lastPaymentRub < MIN_LASTPAYMENT_NSIB,
message: `Последний платеж меньше ${MIN_LASTPAYMENT_NSIB} руб. не может быть при наличии НСИБ, укажите большее значение`,
});
}
);
}

View File

@ -0,0 +1,2 @@
export { default as common } from './common';
export { default as validation } from './validation';

View File

@ -0,0 +1,64 @@
import validatePaymentsTable from '../lib/validation';
import { MIN_LASTPAYMENT_NSIB } from '@/constants/values';
import type { ReactionsContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { comparer, reaction, toJS } from 'mobx';
export default function reactions({ store }: ReactionsContext) {
const { $calculation, $tables } = store;
const validationHelper = new ValidationHelper();
reaction(
() => {
const payments = toJS($tables.payments.values);
const graphType = $calculation.element('radioGraphType').getValue();
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStart = $calculation.element('selectHighSeasonStart').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
graphType,
highSeasonStart,
leasingPeriod,
payments,
seasonType,
};
},
() => {
validationHelper.removeErrors();
const errorText = validatePaymentsTable(store);
if (errorText) {
$tables.payments.validate({
helper: validationHelper,
invalid: errorText !== null,
message: errorText,
});
}
},
{
delay: 50,
equals: comparer.structural,
}
);
reaction(
() => {
const lastPaymentRub = $calculation.element('tbxLastPaymentRub').getValue();
const insNSIB = $calculation.element('selectInsNSIB').getValue();
return {
insNSIB,
lastPaymentRub,
};
},
({ lastPaymentRub, insNSIB }) => {
$calculation.element('tbxLastPaymentRub').validate({
invalid: Boolean(insNSIB) && lastPaymentRub < MIN_LASTPAYMENT_NSIB,
message: `Последний платеж меньше ${MIN_LASTPAYMENT_NSIB} руб. не может быть при наличии НСИБ, укажите большее значение`,
});
}
);
}

View File

@ -5,7 +5,7 @@ import type { ReactionsContext } from '@/process/types';
import { reaction } from 'mobx';
import { makeDisposable } from 'tools';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
reaction(

View File

@ -7,7 +7,7 @@ import { autorun } from 'mobx';
dayjs.extend(utc);
export default function computedReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
autorun(

View File

@ -5,7 +5,7 @@ import type { ReactionsContext } from '@/process/types';
import { reaction } from 'mobx';
import { round } from 'tools';
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
export default function reactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(

View File

@ -4,7 +4,7 @@ import type { ReactionsContext } from '../types';
import * as CRMTypes from '@/graphql/crm.types';
import { reaction } from 'mobx';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**

View File

@ -19,7 +19,7 @@ import { reaction } from 'mobx';
*/
/* eslint-enable */
export function computedReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
reaction(
@ -98,6 +98,3 @@ export function computedReactions({ store, apolloClient }: ReactionsContext) {
}
);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function commonReactions({ store }: ReactionsContext) {}

View File

@ -15,7 +15,21 @@ const { fillAgentRewardReaction, fillAgentRewardSummReaction, validateAgentRewar
dayjs.extend(utc);
export function fillReactions({ store, apolloClient }: ReactionsContext) {
class Helper {
public enabled: boolean;
/**
*
*/
constructor() {
this.enabled = false;
}
public set = (value: boolean) => {
this.enabled = value;
};
}
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**
@ -94,24 +108,6 @@ export function fillReactions({ store, apolloClient }: ReactionsContext) {
rewardConditionField: 'selectFinDepartmentRewardCondtion',
rewardSummField: 'tbxFinDepartmentRewardSumm',
});
}
class Helper {
public enabled: boolean;
/**
*
*/
constructor() {
this.enabled = false;
}
public set = (value: boolean) => {
this.enabled = value;
};
}
export function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**
* Добавить реакцию на изменение списка в поле selectDealerRewardCondition :
@ -526,7 +522,7 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
}
}
export function validationReactions({ store, apolloClient }: ReactionsContext) {
export function validation({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
validateAgentRewardSumm(store, apolloClient, {

View File

@ -0,0 +1,17 @@
import * as agents from './agents';
import * as leaseback from './leaseback';
import * as supplier from './supplier';
import type { ReactionsContext } from '@/process/types';
function common(context: ReactionsContext) {
agents.common(context);
leaseback.common(context);
supplier.common(context);
}
function validation(context: ReactionsContext) {
agents.validation(context);
supplier.validation(context);
}
export { common, validation };

View File

@ -2,7 +2,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import type { ReactionsContext } from '@/process/types';
import { autorun, reaction } from 'mobx';
export default function leasebackReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation, $tables } = store;
/**
* Дополнить реакцию на изменение поля Салон приобретения selectDealer:

View File

@ -9,7 +9,7 @@ import { normalizeOptions } from 'tools/entity';
dayjs.extend(utc);
export function commonReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation, $process } = store;
/**
@ -158,7 +158,7 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) {
);
}
export function validationReactions({ store, apolloClient }: ReactionsContext) {
export function validation({ store, apolloClient }: ReactionsContext) {
createReactions.validateAgentRewardSumm(store, apolloClient, {
rewardConditionField: 'selectDealerRewardCondition',
rewardSummField: 'tbxDealerRewardSumm',

View File

@ -4,7 +4,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
export function common({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
/**