diff --git a/Components/Calculation/Form/Insurance/InsuranceTable/types.ts b/Components/Calculation/Form/Insurance/InsuranceTable/types.ts index 188e0dc..3805ba7 100644 --- a/Components/Calculation/Form/Insurance/InsuranceTable/types.ts +++ b/Components/Calculation/Form/Insurance/InsuranceTable/types.ts @@ -14,7 +14,7 @@ export type RowValues = { export type Values = Exclude; export type RowOptions = { - [ValueName in Values]?: BaseOption[]; + [ValueName in Values]?: BaseOption[]; } & { key: Keys }; export type RowStatuses = Record & { diff --git a/Components/Calculation/config/map/values.ts b/Components/Calculation/config/map/values.ts index d07bd71..48f9e93 100644 --- a/Components/Calculation/config/map/values.ts +++ b/Components/Calculation/config/map/values.ts @@ -151,7 +151,7 @@ export type ElementsTypes = { [Key in keyof ElementsValues]: CalculationValues[ElementsValues[Key]]; }; -export type Elements = keyof ElementsValues; +export type Elements = keyof ElementsTypes; export function getValueName(elementName: Elements) { return elementsToValues[elementName]; diff --git a/Elements/types.ts b/Elements/types.ts index e8d8cd3..81d9d59 100644 --- a/Elements/types.ts +++ b/Elements/types.ts @@ -1,14 +1,14 @@ export type Status = 'Default' | 'Disabled' | 'Loading' | 'Hidden'; -export type BaseElementProps = { - value: ValueType; - setValue: (value: ValueType) => void; +export type BaseElementProps = { + value: Value; + setValue: (value: Value) => void; status?: Status; isValid?: boolean; help?: string; }; -export type BaseOption = { +export type BaseOption = { label: string; - value: any; + value: Value; }; diff --git a/config/default-options.ts b/config/default-options.ts index 1273e97..e1a73bf 100644 --- a/config/default-options.ts +++ b/config/default-options.ts @@ -366,29 +366,25 @@ const defaultOptions: CalculationOptions = { selectObjectTypeTax: [ { label: 'Автобус', - type: 'D', + value: 100_000_000, }, { label: 'Легковой', - type: 'B', + value: 100_000_001, }, { label: 'Грузовой', - type: 'C', + value: 100_000_002, }, { label: 'Спецтехника', - type: 'T', + value: 100_000_003, }, { label: 'Мотоцикл', - type: 'A', + value: 100_000_004, }, - ].map((v, i) => ({ - ...v, - value: 100_000_000 + i, - })), - + ], selectLead: [], selectOpportunity: [], selectQuote: [], diff --git a/stores/calculation/options/index.ts b/stores/calculation/options/index.ts index a249faa..00903af 100644 --- a/stores/calculation/options/index.ts +++ b/stores/calculation/options/index.ts @@ -1,6 +1,6 @@ /* eslint-disable object-curly-newline */ /* eslint-disable unicorn/prefer-set-has */ -import type { Elements } from 'Components/Calculation/config/map/values'; +import type { Elements, ElementsTypes } from 'Components/Calculation/config/map/values'; import defaultOptions from 'config/default-options'; import type { BaseOption } from 'Elements/types'; import { makeAutoObservable } from 'mobx'; @@ -34,7 +34,7 @@ export default class OptionsStore { this.options = initialOptions; }; - getOption(elementName: Elements) { + getOption(elementName: T) { const value = this.root.$calculation.$values.getElementValue(elementName); return this.options[elementName]?.find((x) => x.value === value); @@ -46,8 +46,16 @@ export default class OptionsStore { return options; } - setElementOptions = (elementName: Elements, options: BaseOption[]) => { - this.options[elementName] = options; + setElementOptions = ( + elementName: T, + options: BaseOption[] + ) => { + /** + * TODO: use T istead of any in BaseOption type + * at this moment T causes typescript error + * but infer works just perfect + */ + this.options[elementName] = options as BaseOption[]; /** * Проверяем, что значение есть в новом списке, иначе сбрасываем значение @@ -62,11 +70,15 @@ export default class OptionsStore { * (для элементов из списка {@link AUTO_SET_VALUE_ELEMENTS}) */ if (options?.length === 1 && AUTO_SET_VALUE_ELEMENTS.includes(elementName)) { - this.root.$calculation.$values.setElementValue(elementName, options.at(0)?.value); + const optionValue = options.at(0)?.value; + + if (optionValue) { + this.root.$calculation.$values.setElementValue(elementName, optionValue); + } } }; - resetOption = (elementName: Elements) => { + resetOption = (elementName: T) => { this.options[elementName] = defaultOptions[elementName]; }; @@ -83,7 +95,11 @@ export default class OptionsStore { } (Object.keys(options) as Elements[]).forEach((elementName) => { - this.setElementOptions(elementName, options[elementName]!); + const elementOptions = options[elementName]; + + if (elementOptions) { + this.setElementOptions(elementName, elementOptions); + } }); }; } diff --git a/stores/calculation/options/types.ts b/stores/calculation/options/types.ts index f0caf3c..4bbf7e0 100644 --- a/stores/calculation/options/types.ts +++ b/stores/calculation/options/types.ts @@ -1,4 +1,6 @@ -import type { Elements } from 'Components/Calculation/config/map/values'; +import type { Elements, ElementsTypes } from 'Components/Calculation/config/map/values'; import type { BaseOption } from 'Elements/types'; -export type CalculationOptions = Record; +export type CalculationOptions = { + [ElementName in Elements]: BaseOption[]; +}; diff --git a/stores/calculation/values/types.ts b/stores/calculation/values/types.ts index 84fe85f..e1af1a1 100644 --- a/stores/calculation/values/types.ts +++ b/stores/calculation/values/types.ts @@ -15,60 +15,22 @@ export type CalculationValues = { firstPaymentRub: number; lastPaymentPerc: number; lastPaymentRub: number; - lastPaymentRule: 100_000_000 | 100_000_001 | 100_000_002 | null; + lastPaymentRule: number | null; importProgram: string | null; importProgramSum: number; addEquipmentPrice: number; redemptionPaymentSum: number; - balanceHolder: 100_000_000 | 100_000_001 | null; - graphType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null; - + balanceHolder: number | null; + graphType: number | null; parmentsDecreasePercent: number; - seasonType: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | null; - highSeasonStart: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | 100_000_008 - | 100_000_009 - | 100_000_010 - | 100_000_011 - | 100_000_012 - | null; + seasonType: number | null; + highSeasonStart: number | null; comissionPerc: number; comissionRub: number; saleBonus: number; IRR_Perc: number; leaseObjectType: string | null; - deliveryTime: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | 100_000_008 - | 100_000_009 - | 100_000_010 - | 100_000_011 - | 100_000_012 - | null; + deliveryTime: number | null; leaseObjectCount: number; withTrailer: boolean; leaseObjectUsed: boolean; @@ -79,32 +41,11 @@ export type CalculationValues = { model: string | null; configuration: string | null; leaseObjectYear: number; - engineType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null; - leaseObjectCategory: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null; + engineType: number | null; + leaseObjectCategory: number | null; leaseObjectMotorPower: number; engineVolume: number; - leaseObjectUseFor: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | 100_000_008 - | 100_000_009 - | 100_000_010 - | 100_000_011 - | 100_000_012 - | 100_000_013 - | 100_000_014 - | 100_000_015 - | 100_000_016 - | 100_000_017 - | 100_000_018 - | 100_000_019 - | null; + leaseObjectUseFor: number | null; dealer: string | null; dealerPerson: string | null; dealerRewardCondition: string | null; @@ -128,8 +69,8 @@ export type CalculationValues = { GPSModel: string | null; regionRegistration: string | null; townRegistration: string | null; - infuranceOPF: 100_000_000 | 100_000_001 | null; - insKaskoType: 100_000_000 | 100_000_001 | null; + infuranceOPF: number | null; + insKaskoType: number | null; insDecentral: boolean; insFranchise: number; insUnlimitDrivers: boolean; @@ -145,22 +86,13 @@ export type CalculationValues = { technicalCardQuote: boolean; NSIB: boolean; quoteName: string | null; - quoteContactGender: 100_000_000 | 100_000_001 | null; + quoteContactGender: number | null; quoteRedemptionGraph: boolean; showFinGAP: boolean; tarif: string | null; creditRate: number; rate: string | null; - requirementTelematic: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | null; + requirementTelematic: number | null; minPriceChange: number; maxPriceChange: number; importerRewardPerc: number; @@ -172,44 +104,15 @@ export type CalculationValues = { telematic: string | null; tracker: string | null; mileage: number; - calcType: 100_000_000 | 100_000_001 | null; + calcType: number | null; totalPayments: number; - objectRegistration: 100_000_000 | 100_000_001 | null; + objectRegistration: number | null; objectRegionRegistration: string | null; vehicleTaxInYear: number; vehicleTaxInLeasingPeriod: number; - objectCategoryTax: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | 100_000_006 - | 100_000_007 - | 100_000_008 - | 100_000_009 - | 100_000_010 - | 100_000_011 - | 100_000_012 - | 100_000_013 - | 100_000_014 - | 100_000_015 - | 100_000_016 - | 100_000_017 - | 100_000_018 - | 100_000_019 - | 100_000_020 - | null; - objectTypeTax: - | 100_000_000 - | 100_000_001 - | 100_000_002 - | 100_000_003 - | 100_000_004 - | 100_000_005 - | null; - typePTS: 100_000_000 | 100_000_001 | null; + objectCategoryTax: number | null; + objectTypeTax: number | null; + typePTS: number | null; legalClientRegion: string | null; legalClientTown: string | null; subsidy: string | null;