stores: add calculation statuses store

This commit is contained in:
Chika 2022-04-29 22:25:43 +03:00
parent bdd84c7e59
commit 0c8114a877
4 changed files with 198 additions and 1 deletions

View File

@ -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';

View File

@ -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);
}
}

View File

@ -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<Record<Elements, Status>>;
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);
}
}

View File

@ -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;