store: add CalculationStore (values)

This commit is contained in:
Chika 2022-04-29 12:50:28 +03:00
parent e6433f122c
commit b733da22cc
9 changed files with 210 additions and 2 deletions

View File

@ -16,6 +16,14 @@ const nextConfig = {
},
];
},
experimental: {
modularizeImports: {
lodash: {
transform: 'lodash/{{member}}',
preventFullImport: true,
},
},
},
};
const plugins = [

View File

@ -17,6 +17,7 @@
"graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0",
"less": "^4.1.2",
"less-loader": "^10.2.0",
"lodash": "^4.17.21",
"mobx": "^6.5.0",
"mobx-react-lite": "^3.3.0",
"next": "12.1.5",
@ -30,6 +31,7 @@
"styled-components": "^5.3.5"
},
"devDependencies": {
"@types/lodash": "^4.14.182",
"@types/node": "17.0.25",
"@types/react": "18.0.5",
"@types/react-dom": "18.0.1",

View File

@ -0,0 +1,10 @@
import { RootStore } from 'stores/root';
import { ValuesStore } from './values';
export class CalculationStore {
$values: ValuesStore;
constructor(rootStore: RootStore) {
this.$values = new ValuesStore(rootStore);
}
}

141
stores/calculation/types.ts Normal file
View File

@ -0,0 +1,141 @@
export type Values =
| 'lead'
| 'opportunity'
| 'quote'
| 'recalcWithRevision'
| 'product'
| 'clientRisk'
| 'clientType'
| 'leaseObjectPrice'
| 'supplierCurrency'
| 'supplierDiscountRub'
| 'supplierDiscountPerc'
| 'leasingPeriod'
| 'firstPaymentPerc'
| 'firstPaymentRub'
| 'lastPaymentPerc'
| 'lastPaymentRub'
| 'lastPaymentRule'
| 'redemptionPaymentSum'
| 'balanceHolder'
| 'graphType'
| 'parmentsDecreasePercent'
| 'seasonType'
| 'highSeasonStart'
| 'comissionPerc'
| 'comissionRub'
| 'saleBonus'
| 'IRR_Perc'
| 'paymentGraph'
| 'leaseObjectType'
| 'deliveryTime'
| 'leaseObjectRisk'
| 'depreciationGroup'
| 'leaseObjectCount'
| 'withTrailer'
| 'leaseObjectUsed'
| 'maxMass'
| 'countSeats'
| 'maxSpeed'
| 'brand'
| 'model'
| 'configuration'
| 'leaseObjectYear'
| 'engineType'
| 'leaseObjectCategory'
| 'leaseObjectMotorPower'
| 'engineVolume'
| 'leaseObjectUseFor'
| 'dealer'
| 'dealerPerson'
| 'dealerRewardCondition'
| 'dealerRewardSumm'
| 'dealerBroker'
| 'dealerBrokerRewardCondition'
| 'dealerBrokerRewardSumm'
| 'indAgent'
| 'indAgentRewardCondition'
| 'indAgentRewardSumm'
| 'calcDoubleAgent'
| 'calcDoubleAgentRewardCondition'
| 'calcDoubleAgentRewardSumm'
| 'calcBroker'
| 'calcBrokerRewardCondition'
| 'calcBrokerRewardSum'
| 'calcFinDepartment'
| 'finDepartmentRewardCondtion'
| 'finDepartmentRewardSumm'
| 'GPSBrand'
| 'GPSModel'
| 'regionRegistration'
| 'townRegistration'
| 'infuranceOPF'
| 'insKaskoType'
| 'insDecentral'
| 'insFranchise'
| 'insUnlimitDrivers'
| 'insAgeDrivers'
| 'insExpDrivers'
| 'INNForCalc'
| 'lastPaymentRedemption'
| 'priceWithDiscount'
| 'fullPriceWithDiscount'
| 'costIncrease'
| 'insurance'
| 'registrationQuote'
| 'technicalCardQuote'
| 'NSIB'
| 'quoteName'
| 'quoteContactGender'
| 'quoteRedemptionGraph'
| 'showFinGAP'
| 'tarif'
| 'creditRate'
| 'rate'
| 'requirementTelematic'
| 'maxPriceChange'
| 'importerRewardPerc'
| 'importerRewardRub'
| 'disableChecks'
| 'registration'
| 'insNSIB'
| 'technicalCard'
| 'telematic'
| 'tracker'
| 'mileage'
| 'calcType'
| 'totalPayments'
| 'objectRegistration'
| 'objectRegionRegistration'
| 'vehicleTaxInYear'
| 'vehicleTaxInLeasingPeriod'
| 'objectCategoryTax'
| 'objectTypeTax'
| 'typePTS'
| 'legalClientRegion'
| 'legalClientTown'
| 'subsidy'
| 'subsidySum'
| 'fuelCard'
| 'minPriceChange'
| 'resultTotalGraphwithNDS'
| 'resultPlPrice'
| 'resultPriceUpPr'
| 'resultIRRGraphPerc'
| 'resultIRRNominalPerc'
| 'resultInsKasko'
| 'resultInsOsago'
| 'resultDopProdSum'
| 'resultFirstPayment'
| 'resultLastPayment'
| 'resultTerm'
| 'resultAB_FL'
| 'resultAB_UL'
| 'resultBonusMPL'
| 'resultDopMPLLeasing'
| 'resultBonusDopProd'
| 'resultBonusSafeFinance'
| 'resultFirstPaymentRiskPolicy'
| 'leaseObjectPriceWthtVAT'
| 'VATInLeaseObjectPrice'
| 'engineHours';

View File

@ -0,0 +1,37 @@
import { pick } from 'lodash';
import { makeAutoObservable } from 'mobx';
import { RootStore } from '../root';
import { Values } from './types';
export type CalculationValues = Partial<Record<Values, any>>;
export class ValuesStore {
root: RootStore;
#values: CalculationValues = {};
constructor(rootStore: RootStore) {
makeAutoObservable(this);
this.root = rootStore;
}
hydrate = (initialValues: CalculationValues) => {
this.#values = initialValues;
};
getValue(valueName: Values) {
return this.#values[valueName];
}
getValues(valuesNames: Values[]) {
return pick(this.#values, valuesNames);
}
setValue(valueName: Values, value: any) {
this.#values[valueName] = value;
}
setValues(values: CalculationValues, options: { replace?: boolean }) {
if (options.replace) this.#values = values;
this.#values = Object.assign(this.#values, values);
}
}

View File

@ -9,8 +9,9 @@ export function initializeStore(initialData) {
const _store = store ?? new RootStore();
if (initialData) {
const { user } = initialData;
const { user = null, calculationValues = {} } = initialData;
_store.$user.hydrate(user);
_store.$calculation.$values.hydrate(calculationValues);
}
if (typeof window === 'undefined') return _store;

View File

@ -1,11 +1,15 @@
import { enableStaticRendering } from 'mobx-react-lite';
import { CalculationStore } from './calculation';
import { UserStore } from './user';
enableStaticRendering(typeof window === 'undefined');
export class RootStore {
$user: UserStore;
$calculation: CalculationStore;
constructor() {
this.$user = new UserStore(this);
this.$calculation = new CalculationStore(this);
}
}

View File

@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,

View File

@ -850,6 +850,11 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
"@types/lodash@^4.14.182":
version "4.14.182"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==
"@types/node-fetch@^2.5.10":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.1.tgz#8f127c50481db65886800ef496f20bbf15518975"