elements: check value in options

This commit is contained in:
vchikalkin 2023-02-02 11:28:21 +03:00
parent a5f6805115
commit f53f4b8d66
11 changed files with 308 additions and 176 deletions

View File

@ -1,151 +0,0 @@
import { buildAction, buildOptions, buildReadonly, buildValue } from '../builders';
import type { Elements as ActionElements } from './map/actions';
import type { Elements as ValuesElements } from './map/values';
function wrapElementsBuilders<C, T extends Record<ValuesElements | ActionElements, C>>(arg: T) {
return arg;
}
const builders = wrapElementsBuilders({
cbxRecalcWithRevision: buildValue,
tbxLeaseObjectPrice: buildValue,
tbxLeaseObjectPriceWthtVAT: buildValue,
tbxVATInLeaseObjectPrice: buildValue,
tbxEngineHours: buildValue,
tbxSupplierDiscountRub: buildValue,
tbxSupplierDiscountPerc: buildValue,
tbxLeasingPeriod: buildValue,
tbxFirstPaymentPerc: buildValue,
tbxFirstPaymentRub: buildValue,
tbxLastPaymentPerc: buildValue,
tbxLastPaymentRub: buildValue,
selectImportProgram: buildOptions,
tbxImportProgramSum: buildReadonly,
tbxAddEquipmentPrice: buildValue,
tbxRedemptionPaymentSum: buildValue,
tbxParmentsDecreasePercent: buildValue,
tbxComissionPerc: buildValue,
tbxComissionRub: buildValue,
tbxSaleBonus: buildValue,
tbxIRR_Perc: buildValue,
tbxLeaseObjectCount: buildValue,
cbxWithTrailer: buildValue,
cbxLeaseObjectUsed: buildValue,
tbxMaxMass: buildValue,
tbxCountSeats: buildValue,
tbxMaxSpeed: buildValue,
tbxLeaseObjectYear: buildValue,
tbxLeaseObjectMotorPower: buildValue,
tbxEngineVolume: buildValue,
tbxDealerRewardSumm: buildValue,
tbxDealerBrokerRewardSumm: buildValue,
tbxIndAgentRewardSumm: buildValue,
tbxCalcDoubleAgentRewardSumm: buildValue,
tbxCalcBrokerRewardSum: buildValue,
tbxFinDepartmentRewardSumm: buildValue,
cbxInsDecentral: buildValue,
tbxInsFranchise: buildValue,
cbxInsUnlimitDrivers: buildValue,
tbxInsAgeDrivers: buildValue,
tbxInsExpDrivers: buildValue,
tbxINNForCalc: buildValue,
cbxLastPaymentRedemption: buildValue,
cbxPriceWithDiscount: buildValue,
cbxFullPriceWithDiscount: buildValue,
cbxCostIncrease: buildValue,
cbxInsurance: buildValue,
cbxRegistrationQuote: buildValue,
cbxTechnicalCardQuote: buildValue,
cbxNSIB: buildValue,
tbxQuoteName: buildValue,
cbxQuoteRedemptionGraph: buildValue,
cbxShowFinGAP: buildValue,
tbxCreditRate: buildValue,
tbxMaxPriceChange: buildValue,
tbxImporterRewardPerc: buildValue,
tbxImporterRewardRub: buildValue,
cbxDisableChecks: buildValue,
tbxMileage: buildValue,
tbxTotalPayments: buildValue,
tbxVehicleTaxInYear: buildValue,
tbxVehicleTaxInLeasingPeriod: buildValue,
tbxMinPriceChange: buildValue,
selectProduct: buildOptions,
selectClientRisk: buildOptions,
selectClientType: buildOptions,
selectSupplierCurrency: buildOptions,
selectSeasonType: buildOptions,
selectHighSeasonStart: buildOptions,
selectLeaseObjectType: buildOptions,
selectBrand: buildOptions,
selectModel: buildOptions,
selectConfiguration: buildOptions,
selectLeaseObjectUseFor: buildOptions,
selectLeaseObjectCategory: buildOptions,
selectEngineType: buildOptions,
selectDealer: buildOptions,
selectDealerPerson: buildOptions,
selectDealerRewardCondition: buildOptions,
selectDealerBroker: buildOptions,
selectDealerBrokerRewardCondition: buildOptions,
selectIndAgent: buildOptions,
selectIndAgentRewardCondition: buildOptions,
selectCalcDoubleAgent: buildOptions,
selectCalcDoubleAgentRewardCondition: buildOptions,
selectCalcBroker: buildOptions,
selectCalcBrokerRewardCondition: buildOptions,
selectCalcFinDepartment: buildOptions,
selectFinDepartmentRewardCondtion: buildOptions,
selectGPSBrand: buildOptions,
selectGPSModel: buildOptions,
selectRegionRegistration: buildOptions,
selectTownRegistration: buildOptions,
selectRegistration: buildOptions,
selectInsNSIB: buildOptions,
selectTracker: buildOptions,
selectTelematic: buildOptions,
selectTechnicalCard: buildOptions,
selectTarif: buildOptions,
selectRate: buildOptions,
selectLead: buildOptions,
selectOpportunity: buildOptions,
selectQuote: buildOptions,
selectObjectRegionRegistration: buildOptions,
selectObjectCategoryTax: buildOptions,
selectObjectTypeTax: buildOptions,
selectLegalClientRegion: buildOptions,
selectLegalClientTown: buildOptions,
selectSubsidy: buildOptions,
selectFuelCard: buildOptions,
radioBalanceHolder: buildOptions,
radioLastPaymentRule: buildOptions,
radioGraphType: buildOptions,
radioDeliveryTime: buildOptions,
radioInsKaskoType: buildOptions,
radioInfuranceOPF: buildOptions,
selectRequirementTelematic: buildOptions,
radioQuoteContactGender: buildOptions,
radioCalcType: buildOptions,
radioObjectRegistration: buildOptions,
radioTypePTS: buildOptions,
tbxBonusCoefficient: buildValue,
selectLeasingWithoutKasko: buildOptions,
labelLeaseObjectRisk: buildReadonly,
tbxInsKaskoPriceLeasePeriod: buildReadonly,
labelIrrInfo: buildReadonly,
labelRegistrationDescription: buildReadonly,
labelDepreciationGroup: buildReadonly,
tbxSubsidySum: buildReadonly,
btnCreateKP: buildAction,
btnCalculate: buildAction,
linkDownloadKp: buildReadonly,
linkLeadUrl: buildReadonly,
linkOpportunityUrl: buildReadonly,
linkQuoteUrl: buildReadonly,
});
export default builders;

View File

@ -6,10 +6,10 @@ import { useStore } from 'stores/hooks';
import Link from 'ui/elements/Link';
import Tooltip from 'ui/elements/Tooltip';
import buildReadonly from '../../builders/build-readonly';
import builders from '../elements-builders';
import components from '../elements-components';
import elementsProps from '../elements-props';
import titles from '../elements-titles';
import types from '../elements-types';
import map from '../map';
import type { RenderProps } from './types';
@ -26,7 +26,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.selectLead;
const Component = components.selectLead;
const props = elementsProps.selectLead;
const builder = builders.selectLead;
const { builder } = types.selectLead();
const Element = builder(Component, {
elementName,
@ -58,7 +58,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.selectOpportunity;
const Component = components.selectOpportunity;
const props = elementsProps.selectOpportunity;
const builder = builders.selectOpportunity;
const { builder } = types.selectOpportunity();
const Element = builder(Component, {
elementName,
@ -90,7 +90,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.selectQuote;
const Component = components.selectQuote;
const props = elementsProps.selectQuote;
const builder = builders.selectQuote;
const { builder } = types.selectQuote();
const Element = builder(Component, {
elementName,
@ -122,7 +122,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.tbxVehicleTaxInYear;
const Component = components.tbxVehicleTaxInYear;
const props = elementsProps.tbxVehicleTaxInYear;
const builder = builders.tbxVehicleTaxInYear;
const { builder } = types.tbxVehicleTaxInYear();
const Element = builder(Component, {
elementName,
@ -147,7 +147,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.selectHighSeasonStart;
const Component = components.selectHighSeasonStart;
const props = elementsProps.selectHighSeasonStart;
const builder = builders.selectHighSeasonStart;
const { builder } = types.selectHighSeasonStart();
const Element = builder(Component, {
elementName,
@ -171,7 +171,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const valueName = map.selectSeasonType;
const Component = components.selectSeasonType;
const props = elementsProps.selectSeasonType;
const builder = builders.selectSeasonType;
const { builder } = types.selectSeasonType();
const Element = builder(Component, {
elementName,

View File

@ -1,9 +1,9 @@
/* eslint-disable object-curly-newline */
import { Container, Head } from 'Components/Layout/Element';
import builders from '../elements-builders';
import components from '../elements-components';
import elementsProps from '../elements-props';
import titles from '../elements-titles';
import types from '../elements-types';
import map from '../map';
const render = Object.keys(map).reduce((acc, elementName) => {
@ -11,7 +11,7 @@ const render = Object.keys(map).reduce((acc, elementName) => {
const valueName = map[elementName];
const Component = components[elementName];
const props = elementsProps[elementName];
const builder = builders[elementName];
const { builder } = types[elementName]();
const Element = builder(Component, {
elementName,

View File

@ -0,0 +1,182 @@
import { buildAction, buildOptions, buildReadonly, buildValue } from '../builders';
import type { Elements as ActionElements } from './map/actions';
import type { Elements as ValuesElements } from './map/values';
type ElementTypes = 'Value' | 'Readonly' | 'Options' | 'Action';
type Builders = typeof buildValue | typeof buildReadonly | typeof buildOptions | typeof buildAction;
type GetType = () => {
typeName: ElementTypes;
builder: Builders;
};
function wrapTypeGetters<G extends GetType, E extends Record<ElementTypes, G>>(arg: E) {
return arg;
}
const t = wrapTypeGetters({
Value: () => ({
typeName: 'Value',
builder: buildValue,
}),
Readonly: () => ({
typeName: 'Readonly',
builder: buildReadonly,
}),
Options: () => ({
typeName: 'Options',
builder: buildOptions,
}),
Action: () => ({
typeName: 'Action',
builder: buildAction,
}),
});
function wrapElementsTypes<T, E extends Record<ValuesElements | ActionElements, T>>(arg: E) {
return arg;
}
const types = wrapElementsTypes({
cbxRecalcWithRevision: t.Value,
tbxLeaseObjectPrice: t.Value,
tbxLeaseObjectPriceWthtVAT: t.Value,
tbxVATInLeaseObjectPrice: t.Value,
tbxEngineHours: t.Value,
tbxSupplierDiscountRub: t.Value,
tbxSupplierDiscountPerc: t.Value,
tbxLeasingPeriod: t.Value,
tbxFirstPaymentPerc: t.Value,
tbxFirstPaymentRub: t.Value,
tbxLastPaymentPerc: t.Value,
tbxLastPaymentRub: t.Value,
selectImportProgram: t.Options,
tbxImportProgramSum: t.Readonly,
tbxAddEquipmentPrice: t.Value,
tbxRedemptionPaymentSum: t.Value,
tbxParmentsDecreasePercent: t.Value,
tbxComissionPerc: t.Value,
tbxComissionRub: t.Value,
tbxSaleBonus: t.Value,
tbxIRR_Perc: t.Value,
tbxLeaseObjectCount: t.Value,
cbxWithTrailer: t.Value,
cbxLeaseObjectUsed: t.Value,
tbxMaxMass: t.Value,
tbxCountSeats: t.Value,
tbxMaxSpeed: t.Value,
tbxLeaseObjectYear: t.Value,
tbxLeaseObjectMotorPower: t.Value,
tbxEngineVolume: t.Value,
tbxDealerRewardSumm: t.Value,
tbxDealerBrokerRewardSumm: t.Value,
tbxIndAgentRewardSumm: t.Value,
tbxCalcDoubleAgentRewardSumm: t.Value,
tbxCalcBrokerRewardSum: t.Value,
tbxFinDepartmentRewardSumm: t.Value,
cbxInsDecentral: t.Value,
tbxInsFranchise: t.Value,
cbxInsUnlimitDrivers: t.Value,
tbxInsAgeDrivers: t.Value,
tbxInsExpDrivers: t.Value,
tbxINNForCalc: t.Value,
cbxLastPaymentRedemption: t.Value,
cbxPriceWithDiscount: t.Value,
cbxFullPriceWithDiscount: t.Value,
cbxCostIncrease: t.Value,
cbxInsurance: t.Value,
cbxRegistrationQuote: t.Value,
cbxTechnicalCardQuote: t.Value,
cbxNSIB: t.Value,
tbxQuoteName: t.Value,
cbxQuoteRedemptionGraph: t.Value,
cbxShowFinGAP: t.Value,
tbxCreditRate: t.Value,
tbxMaxPriceChange: t.Value,
tbxImporterRewardPerc: t.Value,
tbxImporterRewardRub: t.Value,
cbxDisableChecks: t.Value,
tbxMileage: t.Value,
tbxTotalPayments: t.Value,
tbxVehicleTaxInYear: t.Value,
tbxVehicleTaxInLeasingPeriod: t.Value,
tbxMinPriceChange: t.Value,
selectProduct: t.Options,
selectClientRisk: t.Options,
selectClientType: t.Options,
selectSupplierCurrency: t.Options,
selectSeasonType: t.Options,
selectHighSeasonStart: t.Options,
selectLeaseObjectType: t.Options,
selectBrand: t.Options,
selectModel: t.Options,
selectConfiguration: t.Options,
selectLeaseObjectUseFor: t.Options,
selectLeaseObjectCategory: t.Options,
selectEngineType: t.Options,
selectDealer: t.Options,
selectDealerPerson: t.Options,
selectDealerRewardCondition: t.Options,
selectDealerBroker: t.Options,
selectDealerBrokerRewardCondition: t.Options,
selectIndAgent: t.Options,
selectIndAgentRewardCondition: t.Options,
selectCalcDoubleAgent: t.Options,
selectCalcDoubleAgentRewardCondition: t.Options,
selectCalcBroker: t.Options,
selectCalcBrokerRewardCondition: t.Options,
selectCalcFinDepartment: t.Options,
selectFinDepartmentRewardCondtion: t.Options,
selectGPSBrand: t.Options,
selectGPSModel: t.Options,
selectRegionRegistration: t.Options,
selectTownRegistration: t.Options,
selectRegistration: t.Options,
selectInsNSIB: t.Options,
selectTracker: t.Options,
selectTelematic: t.Options,
selectTechnicalCard: t.Options,
selectTarif: t.Options,
selectRate: t.Options,
selectLead: t.Options,
selectOpportunity: t.Options,
selectQuote: t.Options,
selectObjectRegionRegistration: t.Options,
selectObjectCategoryTax: t.Options,
selectObjectTypeTax: t.Options,
selectLegalClientRegion: t.Options,
selectLegalClientTown: t.Options,
selectSubsidy: t.Options,
selectFuelCard: t.Options,
radioBalanceHolder: t.Options,
radioLastPaymentRule: t.Options,
radioGraphType: t.Options,
radioDeliveryTime: t.Options,
radioInsKaskoType: t.Options,
radioInfuranceOPF: t.Options,
selectRequirementTelematic: t.Options,
radioQuoteContactGender: t.Options,
radioCalcType: t.Options,
radioObjectRegistration: t.Options,
radioTypePTS: t.Options,
tbxBonusCoefficient: t.Value,
selectLeasingWithoutKasko: t.Options,
labelLeaseObjectRisk: t.Readonly,
tbxInsKaskoPriceLeasePeriod: t.Readonly,
labelIrrInfo: t.Readonly,
labelRegistrationDescription: t.Readonly,
labelDepreciationGroup: t.Readonly,
tbxSubsidySum: t.Readonly,
btnCreateKP: t.Action,
btnCalculate: t.Action,
linkDownloadKp: t.Readonly,
linkLeadUrl: t.Readonly,
linkOpportunityUrl: t.Readonly,
linkQuoteUrl: t.Readonly,
});
export default types;

View File

@ -80,7 +80,7 @@ const defaultValues: CalculationValues = {
importerRewardRub: 0,
disableChecks: false,
insFranchise: 0,
rate: 'BASE',
rate: null,
calcType: 100_000_000,
totalPayments: 0,
vehicleTaxInYear: 0,

View File

@ -84,6 +84,21 @@ query GetTarif($tarifId: Uuid!) {
}
}
query GetRates($currentDate: DateTime) {
evo_rates(
statecode: 0
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
label: evo_name
value: evo_rateid
evo_id
evo_tarifs {
evo_tarifid
}
}
}
query GetProducts($currentDate: DateTime) {
evo_baseproducts(
statecode: 0

View File

@ -177,6 +177,13 @@ export type GetTarifQueryVariables = Exact<{
export type GetTarifQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array<number> | null, evo_seasons_type_exception: Array<number> | null, evo_min_decreasing_perc: number | null } | null };
export type GetRatesQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
export type GetRatesQuery = { __typename?: 'Query', evo_rates: Array<{ __typename?: 'evo_rate', evo_id: string | null, label: string | null, value: string | null, evo_tarifs: Array<{ __typename?: 'evo_tarif', evo_tarifid: string | null } | null> | null } | null> | null };
export type GetProductsQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
@ -402,6 +409,7 @@ export const GetQuotesDocument = {"kind":"Document","definitions":[{"kind":"Oper
export const GetQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}}]}}]} as unknown as DocumentNode<GetQuoteQuery, GetQuoteQueryVariables>;
export const GetTarifsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarifs"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarifs"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_delivery_time"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_used"}}]}}]}}]} as unknown as DocumentNode<GetTarifsQuery, GetTarifsQueryVariables>;
export const GetTarifDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarif"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarif"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_tarifid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graphtype_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_seasons_type_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_decreasing_perc"}}]}}]}}]} as unknown as DocumentNode<GetTarifQuery, GetTarifQueryVariables>;
export const GetRatesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRates"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_rates"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_rateid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_tarifs"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarifid"}}]}}]}}]}}]} as unknown as DocumentNode<GetRatesQuery, GetRatesQueryVariables>;
export const GetProductsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetProducts"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproducts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_relation"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000000"}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}}]}}]} as unknown as DocumentNode<GetProductsQuery, GetProductsQueryVariables>;
export const GetProductDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetProduct"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"productId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproduct"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_baseproductid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"productId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_calculation_method"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}}]}}]}}]}}]} as unknown as DocumentNode<GetProductQuery, GetProductQueryVariables>;
export const GetSubsidiesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSubsidies"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_subsidies"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_subsidyid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_subsidy_type"}}]}}]}}]} as unknown as DocumentNode<GetSubsidiesQuery, GetSubsidiesQueryVariables>;

View File

@ -107,4 +107,36 @@ export default function valuesReactions({ store, apolloClient }: ReactionsContex
() => $process.has('LoadKP')
);
reaction(
() => $calculation.element('selectTarif').getValue(),
async (tarifId) => {
if (!tarifId) {
$calculation.element('selectRate').resetValue();
return;
}
const currentDate = dayjs().utc(false).toISOString();
const {
data: { evo_rates },
} = await apolloClient.query({
query: CRMTypes.GetRatesDocument,
variables: {
currentDate,
},
});
const rates = evo_rates?.filter((rate) =>
rate?.evo_tarifs?.filter((tarif) => tarif?.evo_tarifid === tarifId)
);
const baseRate = rates?.find((x) => x?.evo_id === 'BASE');
$calculation
.element('selectRate')
.setOptions(normalizeOptions(rates))
.setValue(baseRate?.value ?? null);
}
);
}

View File

@ -0,0 +1,58 @@
import types from 'Components/Calculation/config/elements-types';
import type * as Values from 'Components/Calculation/config/map/values';
import { reaction } from 'mobx';
import type { BaseOption } from 'ui/elements/types';
import type CalculationStore from '.';
export function hasInvalidValue(value: unknown, options: BaseOption<unknown>[]) {
if (value === null) {
return false;
}
return (value && !options?.length) || !options.some((x) => x.value === value);
}
export function createReactions($calculation: CalculationStore) {
/**
* Проверяем, что выбранное значение элемента есть в списке
*/
(Object.keys(types) as Values.Elements[]).forEach((elementName) => {
const type = types[elementName];
if (type().typeName !== 'Options') {
return;
}
const element = $calculation.element(elementName);
reaction(
() => {
const options = element.getOptions();
const value = element.getValue();
return {
value,
options,
};
},
({ value, options }) => {
element.validate({
invalid: hasInvalidValue(value, options),
message: 'Выбранное значение отсутствует в списке',
});
},
{
delay: 100,
}
);
reaction(
() => element.getOptions(),
(options) => {
const value = element.getValue();
if (hasInvalidValue(value, options)) {
element.resetValue();
}
}
);
});
}

View File

@ -7,6 +7,7 @@ import type RootStore from 'stores/root';
import Validation from 'stores/validation';
import type { BaseOption } from 'ui/elements/types';
import type { RemoveError, ValidationParams } from '../validation/types';
import { createReactions } from './helpers';
import OptionsStore from './options';
import StatusStore from './statuses';
import ValuesStore from './values';
@ -22,6 +23,8 @@ export default class CalculationStore {
this.$status = new StatusStore(rootStore);
this.$options = new OptionsStore(rootStore);
this.$validation = observable.object({});
createReactions(this);
}
private createElementValidation = <E extends Values.Elements>(elementName: E) => {

View File

@ -26,19 +26,6 @@ export default class OptionsStore {
return options;
}
private checkValueInOptions = (elementName: Elements) => {
/**
* Проверяем, что значение есть в новом списке, иначе сбрасываем значение
*/
const value = this.root.$calculation.element(elementName).getValue();
if (
!this.options[elementName]?.length ||
!this.options[elementName].some((x) => x.value === value)
) {
this.root.$calculation.element(elementName).resetValue();
}
};
setOptions = <T extends Elements>(elementName: T, options: BaseOption<ElementsTypes[T]>[]) => {
/**
* TODO: use T instead of any in BaseOption type
@ -46,8 +33,6 @@ export default class OptionsStore {
* but infer works just perfect
*/
this.options[elementName] = options as BaseOption<any>[];
this.checkValueInOptions(elementName);
};
resetOptions = <T extends Elements>(elementName: T) => {