diff --git a/Components/Calculation/types/elements.ts b/Components/Calculation/types/elements.ts new file mode 100644 index 0000000..5d3d781 --- /dev/null +++ b/Components/Calculation/types/elements.ts @@ -0,0 +1,156 @@ +export type Elements = + | 'selectLead' + | 'selectOpportunity' + | 'selectQuote' + | 'cbxRecalcWithRevision' + | 'selectProduct' + | 'selectClientRisk' + | 'selectClientType' + | 'tbxLeaseObjectPrice' + | 'selectSupplierCurrency' + | 'tbxSupplierDiscountRub' + | 'tbxSupplierDiscountPerc' + | 'tbxLeasingPeriod' + | 'tbxFirstPaymentPerc' + | 'tbxFirstPaymentRub' + | 'tbxLastPaymentPerc' + | 'tbxLastPaymentRub' + | 'radioLastPaymentRule' + | 'tbxRedemptionPaymentSum' + | 'radioBalanceHolder' + | 'radioGraphType' + | 'tbxParmentsDecreasePercent' + | 'selectSeasonType' + | 'selectHighSeasonStart' + | 'tbxComissionPerc' + | 'tbxComissionRub' + | 'tbxSaleBonus' + | 'tbxIRR_Perc' + | 'selectLeaseObjectType' + | 'radioDeliveryTime' + | 'labelDepreciationGroup' + | 'tbxLeaseObjectCount' + | 'cbxWithTrailer' + | 'cbxLeaseObjectUsed' + | 'tbxMaxMass' + | 'tbxCountSeats' + | 'tbxMaxSpeed' + | 'selectBrand' + | 'selectModel' + | 'selectConfiguration' + | 'tbxLeaseObjectYear' + | 'selectEngineType' + | 'selectLeaseObjectCategory' + | 'tbxLeaseObjectMotorPower' + | 'tbxEngineVolume' + | 'selectLeaseObjectUseFor' + | 'selectDealer' + | 'selectDealerPerson' + | 'selectDealerRewardCondition' + | 'tbxDealerRewardSumm' + | 'selectDealerBroker' + | 'selectDealerBrokerRewardCondition' + | 'tbxDealerBrokerRewardSumm' + | 'selectIndAgent' + | 'selectIndAgentRewardCondition' + | 'tbxIndAgentRewardSumm' + | 'selectCalcDoubleAgent' + | 'selectCalcDoubleAgentRewardCondition' + | 'tbxCalcDoubleAgentRewardSumm' + | 'selectCalcBroker' + | 'selectCalcBrokerRewardCondition' + | 'tbxCalcBrokerRewardSum' + | 'selectCalcFinDepartment' + | 'selectFinDepartmentRewardCondtion' + | 'tbxFinDepartmentRewardSumm' + | 'selectGPSBrand' + | 'selectGPSModel' + | 'selectRegionRegistration' + | 'selectTownRegistration' + | 'radioInfuranceOPF' + | 'radioInsKaskoType' + | 'cbxInsDecentral' + | 'tbxInsFranchise' + | 'cbxInsUnlimitDrivers' + | 'tbxInsAgeDrivers' + | 'tbxInsExpDrivers' + | 'tbxINNForCalc' + | 'cbxLastPaymentRedemption' + | 'cbxPriceWithDiscount' + | 'cbxFullPriceWithDiscount' + | 'cbxCostIncrease' + | 'cbxInsurance' + | 'cbxRegistrationQuote' + | 'cbxTechnicalCardQuote' + | 'cbxNSIB' + | 'tbxQuoteName' + | 'radioQuoteContactGender' + | 'cbxQuoteRedemptionGraph' + | 'cbxShowFinGAP' + | 'selectTarif' + | 'tbxCreditRate' + | 'selectRate' + | 'radioRequirementTelematic' + | 'tbxMaxPriceChange' + | 'tbxImporterRewardPerc' + | 'tbxImporterRewardRub' + | 'cbxDisableChecks' + | 'selectRegistration' + | 'selectInsNSIB' + | 'selectTechnicalCard' + | 'selectTelematic' + | 'selectTracker' + | 'tbxMileage' + | 'radioCalcType' + | 'tbxTotalPayments' + | 'radioObjectRegistration' + | 'selectObjectRegionRegistration' + | 'tbxVehicleTaxInYear' + | 'tbxVehicleTaxInLeasingPeriod' + | 'selectObjectCategoryTax' + | 'selectObjectTypeTax' + | 'radioTypePTS' + | 'selectLegalClientRegion' + | 'selectLegalClientTown' + | 'selectSubsidy' + | 'labelSubsidySum' + | 'selectFuelCard' + | 'tbxMinPriceChange' + | 'tbxLeaseObjectPriceWthtVAT' + | 'tbxVATInLeaseObjectPrice' + | 'tbxEngineHours' + + /** Result Elements */ + | 'labelResultTotalGraphwithNDS' + | 'labelResultPlPrice' + | 'labelResultPriceUpPr' + | 'labelResultIRRGraphPerc' + | 'labelResultIRRNominalPerc' + | 'labelResultInsKasko' + | 'labelResultInsOsago' + | 'labelResultDopProdSum' + | 'labelResultFirstPayment' + | 'labelResultLastPayment' + | 'labelResultTerm' + | 'labelResultAB_FL' + | 'labelResultAB_UL' + | 'labelResultBonusMPL' + | 'labelResultDopMPLLeasing' + | 'labelResultBonusDopProd' + | 'labelResultBonusSafeFinance' + | 'labelResultFirstPaymentRiskPolicy' + + /** Button Elements */ + | 'btnCreateKP' + | 'btnCalculate' + + /** Link Elements */ + | 'linkDownloadKp' + + /** Computed Elements */ + | 'labelLeaseObjectRisk' + | 'tbxInsKaskoPriceLeasePeriod' + | 'labelIrrInfo' + | 'labelRegistrationDescription'; + +export type CustomComponents = 'componentElt' | 'componentfinGAP'; diff --git a/stores/calculation/index.ts b/stores/calculation/index.ts index 98dcd32..4f47c61 100644 --- a/stores/calculation/index.ts +++ b/stores/calculation/index.ts @@ -1,10 +1,13 @@ import { RootStore } from 'stores/root'; +import { StatusStore } from './statuses'; import { ValuesStore } from './values'; export class CalculationStore { $values: ValuesStore; + $status: StatusStore; constructor(rootStore: RootStore) { this.$values = new ValuesStore(rootStore); + this.$status = new StatusStore(rootStore); } } diff --git a/stores/calculation/statuses/index.ts b/stores/calculation/statuses/index.ts new file mode 100644 index 0000000..f0ae7b1 --- /dev/null +++ b/stores/calculation/statuses/index.ts @@ -0,0 +1,33 @@ +import { Elements } from 'Components/Calculation/types/elements'; +import { makeAutoObservable } from 'mobx'; +import { RootStore } from 'stores/root'; + +type Status = 'Default' | 'Disabled' | 'Loading' | 'Hidden'; + +export type CalculationStatuses = Partial>; + +export class StatusStore { + root: RootStore; + #statuses: CalculationStatuses = {}; + + constructor(rootStore: RootStore) { + makeAutoObservable(this); + this.root = rootStore; + } + + hydrate = (initialStatuses: CalculationStatuses) => { + this.#statuses = initialStatuses; + }; + + getStatus(elementName: Elements) { + return this.#statuses[elementName]; + } + + setStatus(elementName: Elements, status: Status) { + this.#statuses[elementName] = status; + } + + setStatuses(statuses: CalculationStatuses) { + this.#statuses = Object.assign(this.#statuses, statuses); + } +} diff --git a/stores/index.js b/stores/index.js index 6a13e83..f886725 100644 --- a/stores/index.js +++ b/stores/index.js @@ -9,9 +9,14 @@ export function initializeStore(initialData) { const _store = store ?? new RootStore(); if (initialData) { - const { user = null, calculationValues = {} } = initialData; + const { + user = null, + calculationValues = {}, + calculationStatuses = {}, + } = initialData; _store.$user.hydrate(user); _store.$calculation.$values.hydrate(calculationValues); + _store.$calculation.$status.hydrate(calculationStatuses); } if (typeof window === 'undefined') return _store;