Calculation: refactor store & hydrate data
This commit is contained in:
parent
f4f66ebca4
commit
dfcbf2e49e
@ -1,5 +1,6 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import type { CalculationFilters } from 'stores/calculation/options/types';
|
||||
|
||||
const defaultFilters: Partial<CalculationFilters> = {};
|
||||
const defaultFilters: CalculationFilters = {};
|
||||
|
||||
export default defaultFilters;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { orderBy } from 'lodash';
|
||||
import type { CalculationOptions } from 'stores/calculation/options/types';
|
||||
|
||||
const defaultOptions: Partial<CalculationOptions> = {
|
||||
const defaultOptions: CalculationOptions = {
|
||||
radioLastPaymentRule: [
|
||||
{
|
||||
label: 'равен платежу',
|
||||
@ -388,6 +388,128 @@ const defaultOptions: Partial<CalculationOptions> = {
|
||||
...v,
|
||||
value: 100_000_000 + i,
|
||||
})),
|
||||
|
||||
selectLead: [],
|
||||
selectOpportunity: [],
|
||||
selectQuote: [],
|
||||
cbxRecalcWithRevision: [],
|
||||
selectProduct: [],
|
||||
selectClientRisk: [],
|
||||
selectClientType: [],
|
||||
tbxLeaseObjectPrice: [],
|
||||
tbxLeaseObjectPriceWthtVAT: [],
|
||||
tbxVATInLeaseObjectPrice: [],
|
||||
tbxEngineHours: [],
|
||||
selectSupplierCurrency: [],
|
||||
tbxSupplierDiscountRub: [],
|
||||
tbxSupplierDiscountPerc: [],
|
||||
tbxLeasingPeriod: [],
|
||||
tbxFirstPaymentPerc: [],
|
||||
tbxFirstPaymentRub: [],
|
||||
tbxLastPaymentPerc: [],
|
||||
tbxLastPaymentRub: [],
|
||||
tbxRedemptionPaymentSum: [],
|
||||
tbxParmentsDecreasePercent: [],
|
||||
tbxComissionPerc: [],
|
||||
tbxComissionRub: [],
|
||||
tbxSaleBonus: [],
|
||||
tbxIRR_Perc: [],
|
||||
selectLeaseObjectType: [],
|
||||
labelDepreciationGroup: [],
|
||||
tbxLeaseObjectCount: [],
|
||||
cbxWithTrailer: [],
|
||||
cbxLeaseObjectUsed: [],
|
||||
tbxMaxMass: [],
|
||||
tbxCountSeats: [],
|
||||
tbxMaxSpeed: [],
|
||||
selectBrand: [],
|
||||
selectModel: [],
|
||||
selectConfiguration: [],
|
||||
tbxLeaseObjectYear: [],
|
||||
tbxLeaseObjectMotorPower: [],
|
||||
tbxEngineVolume: [],
|
||||
selectDealer: [],
|
||||
selectDealerPerson: [],
|
||||
selectDealerRewardCondition: [],
|
||||
tbxDealerRewardSumm: [],
|
||||
selectDealerBroker: [],
|
||||
selectDealerBrokerRewardCondition: [],
|
||||
tbxDealerBrokerRewardSumm: [],
|
||||
selectIndAgent: [],
|
||||
selectIndAgentRewardCondition: [],
|
||||
tbxIndAgentRewardSumm: [],
|
||||
selectCalcDoubleAgent: [],
|
||||
selectCalcDoubleAgentRewardCondition: [],
|
||||
tbxCalcDoubleAgentRewardSumm: [],
|
||||
selectCalcBroker: [],
|
||||
selectCalcBrokerRewardCondition: [],
|
||||
tbxCalcBrokerRewardSum: [],
|
||||
selectCalcFinDepartment: [],
|
||||
selectFinDepartmentRewardCondtion: [],
|
||||
tbxFinDepartmentRewardSumm: [],
|
||||
selectGPSBrand: [],
|
||||
selectGPSModel: [],
|
||||
selectRegionRegistration: [],
|
||||
selectTownRegistration: [],
|
||||
cbxInsDecentral: [],
|
||||
tbxInsFranchise: [],
|
||||
cbxInsUnlimitDrivers: [],
|
||||
tbxInsAgeDrivers: [],
|
||||
tbxInsExpDrivers: [],
|
||||
tbxINNForCalc: [],
|
||||
cbxLastPaymentRedemption: [],
|
||||
cbxPriceWithDiscount: [],
|
||||
cbxFullPriceWithDiscount: [],
|
||||
cbxCostIncrease: [],
|
||||
cbxInsurance: [],
|
||||
cbxRegistrationQuote: [],
|
||||
cbxTechnicalCardQuote: [],
|
||||
cbxNSIB: [],
|
||||
tbxQuoteName: [],
|
||||
cbxQuoteRedemptionGraph: [],
|
||||
cbxShowFinGAP: [],
|
||||
selectTarif: [],
|
||||
tbxCreditRate: [],
|
||||
selectRate: [],
|
||||
tbxMaxPriceChange: [],
|
||||
tbxImporterRewardPerc: [],
|
||||
tbxImporterRewardRub: [],
|
||||
cbxDisableChecks: [],
|
||||
selectRegistration: [],
|
||||
selectInsNSIB: [],
|
||||
selectTechnicalCard: [],
|
||||
selectTelematic: [],
|
||||
selectTracker: [],
|
||||
tbxMileage: [],
|
||||
tbxTotalPayments: [],
|
||||
selectObjectRegionRegistration: [],
|
||||
tbxVehicleTaxInYear: [],
|
||||
tbxVehicleTaxInLeasingPeriod: [],
|
||||
selectLegalClientRegion: [],
|
||||
selectLegalClientTown: [],
|
||||
selectSubsidy: [],
|
||||
labelSubsidySum: [],
|
||||
selectFuelCard: [],
|
||||
tbxMinPriceChange: [],
|
||||
labelResultTotalGraphwithNDS: [],
|
||||
labelResultPlPrice: [],
|
||||
labelResultPriceUpPr: [],
|
||||
labelResultIRRGraphPerc: [],
|
||||
labelResultIRRNominalPerc: [],
|
||||
labelResultInsKasko: [],
|
||||
labelResultInsOsago: [],
|
||||
labelResultDopProdSum: [],
|
||||
labelResultFirstPayment: [],
|
||||
labelResultLastPayment: [],
|
||||
labelResultTerm: [],
|
||||
labelResultAB_FL: [],
|
||||
labelResultAB_UL: [],
|
||||
labelResultBonusMPL: [],
|
||||
labelResultDopMPLLeasing: [],
|
||||
labelResultBonusDopProd: [],
|
||||
labelResultBonusSafeFinance: [],
|
||||
labelResultFirstPaymentRiskPolicy: [],
|
||||
linkDownloadKp: [],
|
||||
};
|
||||
|
||||
export default defaultOptions;
|
||||
|
||||
@ -19,6 +19,127 @@ const defaultStatuses: CalculationStatuses = {
|
||||
radioInfuranceOPF: 'Disabled',
|
||||
tbxRedemptionPaymentSum: 'Disabled',
|
||||
tbxLeaseObjectPriceWthtVAT: 'Disabled',
|
||||
selectLead: 'Default',
|
||||
selectOpportunity: 'Default',
|
||||
selectQuote: 'Default',
|
||||
cbxRecalcWithRevision: 'Default',
|
||||
selectProduct: 'Default',
|
||||
selectClientRisk: 'Default',
|
||||
tbxLeaseObjectPrice: 'Default',
|
||||
tbxVATInLeaseObjectPrice: 'Default',
|
||||
tbxEngineHours: 'Default',
|
||||
selectSupplierCurrency: 'Default',
|
||||
tbxSupplierDiscountRub: 'Default',
|
||||
tbxSupplierDiscountPerc: 'Default',
|
||||
tbxLeasingPeriod: 'Default',
|
||||
tbxFirstPaymentPerc: 'Default',
|
||||
tbxFirstPaymentRub: 'Default',
|
||||
tbxLastPaymentPerc: 'Default',
|
||||
tbxLastPaymentRub: 'Default',
|
||||
radioLastPaymentRule: 'Default',
|
||||
radioBalanceHolder: 'Default',
|
||||
radioGraphType: 'Default',
|
||||
tbxParmentsDecreasePercent: 'Default',
|
||||
selectSeasonType: 'Default',
|
||||
selectHighSeasonStart: 'Default',
|
||||
tbxComissionPerc: 'Default',
|
||||
tbxComissionRub: 'Default',
|
||||
tbxSaleBonus: 'Default',
|
||||
tbxIRR_Perc: 'Default',
|
||||
selectLeaseObjectType: 'Default',
|
||||
radioDeliveryTime: 'Default',
|
||||
labelDepreciationGroup: 'Default',
|
||||
tbxLeaseObjectCount: 'Default',
|
||||
cbxWithTrailer: 'Default',
|
||||
cbxLeaseObjectUsed: 'Default',
|
||||
tbxMaxMass: 'Default',
|
||||
tbxCountSeats: 'Default',
|
||||
tbxMaxSpeed: 'Default',
|
||||
selectBrand: 'Default',
|
||||
selectModel: 'Default',
|
||||
selectConfiguration: 'Default',
|
||||
tbxLeaseObjectYear: 'Default',
|
||||
selectEngineType: 'Default',
|
||||
tbxLeaseObjectMotorPower: 'Default',
|
||||
tbxEngineVolume: 'Default',
|
||||
selectLeaseObjectUseFor: 'Default',
|
||||
selectDealer: 'Default',
|
||||
selectDealerPerson: 'Default',
|
||||
selectDealerRewardCondition: 'Default',
|
||||
tbxDealerRewardSumm: 'Default',
|
||||
selectDealerBroker: 'Default',
|
||||
selectDealerBrokerRewardCondition: 'Default',
|
||||
tbxDealerBrokerRewardSumm: 'Default',
|
||||
selectIndAgentRewardCondition: 'Default',
|
||||
tbxIndAgentRewardSumm: 'Default',
|
||||
selectCalcDoubleAgentRewardCondition: 'Default',
|
||||
tbxCalcDoubleAgentRewardSumm: 'Default',
|
||||
selectCalcBrokerRewardCondition: 'Default',
|
||||
tbxCalcBrokerRewardSum: 'Default',
|
||||
selectFinDepartmentRewardCondtion: 'Default',
|
||||
tbxFinDepartmentRewardSumm: 'Default',
|
||||
selectGPSBrand: 'Default',
|
||||
selectGPSModel: 'Default',
|
||||
selectRegionRegistration: 'Default',
|
||||
selectTownRegistration: 'Default',
|
||||
radioInsKaskoType: 'Default',
|
||||
cbxInsDecentral: 'Default',
|
||||
tbxInsFranchise: 'Default',
|
||||
cbxInsUnlimitDrivers: 'Default',
|
||||
tbxInsAgeDrivers: 'Default',
|
||||
tbxInsExpDrivers: 'Default',
|
||||
cbxLastPaymentRedemption: 'Default',
|
||||
cbxPriceWithDiscount: 'Default',
|
||||
cbxFullPriceWithDiscount: 'Default',
|
||||
cbxCostIncrease: 'Default',
|
||||
cbxInsurance: 'Default',
|
||||
cbxRegistrationQuote: 'Default',
|
||||
cbxTechnicalCardQuote: 'Default',
|
||||
cbxNSIB: 'Default',
|
||||
tbxQuoteName: 'Default',
|
||||
radioQuoteContactGender: 'Default',
|
||||
cbxQuoteRedemptionGraph: 'Default',
|
||||
cbxShowFinGAP: 'Default',
|
||||
cbxDisableChecks: 'Default',
|
||||
selectRegistration: 'Default',
|
||||
selectInsNSIB: 'Default',
|
||||
selectTechnicalCard: 'Default',
|
||||
selectRequirementTelematic: 'Default',
|
||||
selectTelematic: 'Default',
|
||||
selectTracker: 'Default',
|
||||
tbxMileage: 'Default',
|
||||
radioCalcType: 'Default',
|
||||
tbxTotalPayments: 'Default',
|
||||
radioObjectRegistration: 'Default',
|
||||
selectObjectRegionRegistration: 'Default',
|
||||
tbxVehicleTaxInYear: 'Default',
|
||||
selectObjectCategoryTax: 'Default',
|
||||
radioTypePTS: 'Default',
|
||||
selectLegalClientRegion: 'Default',
|
||||
selectLegalClientTown: 'Default',
|
||||
selectSubsidy: 'Default',
|
||||
labelSubsidySum: 'Default',
|
||||
selectFuelCard: 'Default',
|
||||
tbxMinPriceChange: 'Default',
|
||||
labelResultTotalGraphwithNDS: 'Default',
|
||||
labelResultPlPrice: 'Default',
|
||||
labelResultPriceUpPr: 'Default',
|
||||
labelResultIRRGraphPerc: 'Default',
|
||||
labelResultIRRNominalPerc: 'Default',
|
||||
labelResultInsKasko: 'Default',
|
||||
labelResultInsOsago: 'Default',
|
||||
labelResultDopProdSum: 'Default',
|
||||
labelResultFirstPayment: 'Default',
|
||||
labelResultLastPayment: 'Default',
|
||||
labelResultTerm: 'Default',
|
||||
labelResultAB_FL: 'Default',
|
||||
labelResultAB_UL: 'Default',
|
||||
labelResultBonusMPL: 'Default',
|
||||
labelResultDopMPLLeasing: 'Default',
|
||||
labelResultBonusDopProd: 'Default',
|
||||
labelResultBonusSafeFinance: 'Default',
|
||||
labelResultFirstPaymentRiskPolicy: 'Default',
|
||||
linkDownloadKp: 'Default',
|
||||
};
|
||||
|
||||
export default defaultStatuses;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import initializeApollo from 'apollo/client';
|
||||
import * as Calculation from 'Components/Calculation';
|
||||
import * as insuranceTableConfig from 'config/tables/insurance-table';
|
||||
import type { GetServerSideProps } from 'next';
|
||||
import Head from 'next/head';
|
||||
import { fetchUser } from 'services/user';
|
||||
@ -60,13 +59,6 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async (ctx) =>
|
||||
props: {
|
||||
user,
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
tables: {
|
||||
insurance: {
|
||||
values: insuranceTableConfig.defaultRows,
|
||||
options: insuranceTableConfig.defaultOptions,
|
||||
statuses: insuranceTableConfig.defaultStatuses,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
/* eslint-disable unicorn/prefer-set-has */
|
||||
import type { Elements } from 'Components/Calculation/config/map/values';
|
||||
import defaultFilters from 'config/default-filters';
|
||||
@ -5,7 +6,7 @@ import defaultOptions from 'config/default-options';
|
||||
import type { BaseOption } from 'Elements/types';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import type { CalculationOptions, Filter } from './types';
|
||||
import type { CalculationFilters, CalculationOptions, Filter } from './types';
|
||||
|
||||
const AUTO_SET_VALUE_ELEMENTS: Elements[] = [
|
||||
'selectProduct',
|
||||
@ -23,16 +24,17 @@ const AUTO_SET_VALUE_ELEMENTS: Elements[] = [
|
||||
|
||||
export default class OptionsStore {
|
||||
root: RootStore;
|
||||
options = defaultOptions;
|
||||
filters = defaultFilters;
|
||||
options: CalculationOptions = defaultOptions;
|
||||
filters: Partial<CalculationFilters> = defaultFilters;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
makeAutoObservable(this);
|
||||
this.root = rootStore;
|
||||
}
|
||||
|
||||
hydrate = (initialOptions: CalculationOptions) => {
|
||||
hydrate = (initialOptions: CalculationOptions, initialFilters: CalculationFilters) => {
|
||||
this.options = initialOptions;
|
||||
this.filters = initialFilters;
|
||||
};
|
||||
|
||||
/** **************** OPTIONS **************** */
|
||||
|
||||
@ -4,4 +4,4 @@ import type { BaseOption } from 'Elements/types';
|
||||
export type CalculationOptions = Record<Elements, BaseOption[]>;
|
||||
|
||||
export type Filter = (options: BaseOption[]) => BaseOption[];
|
||||
export type CalculationFilters = Record<Elements, Filter>;
|
||||
export type CalculationFilters = Partial<Record<Elements, Filter>>;
|
||||
|
||||
@ -8,7 +8,7 @@ import type { CalculationStatuses } from './types';
|
||||
|
||||
export default class StatusStore {
|
||||
root: RootStore;
|
||||
statuses = defaultStatuses;
|
||||
statuses: CalculationStatuses = defaultStatuses;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
makeAutoObservable(this);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Elements } from 'Components/Calculation/config/map/values';
|
||||
import type { Status } from 'Elements/types';
|
||||
|
||||
export type CalculationStatuses = Partial<Record<Elements, Status>>;
|
||||
export type CalculationStatuses = Record<Elements, Status>;
|
||||
|
||||
@ -9,7 +9,7 @@ import type { CalculationValues, Values } from './types';
|
||||
|
||||
export default class ValuesStore {
|
||||
root: RootStore;
|
||||
values = defaultValues;
|
||||
values: CalculationValues = defaultValues;
|
||||
$computed: Computed;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
|
||||
@ -18,8 +18,9 @@ export function initializeStore(initialData) {
|
||||
if (calculation?.values) _store.$calculation.$values.hydrate(calculation.values);
|
||||
if (calculation?.statuses) _store.$calculation.$status.hydrate(calculation.statuses);
|
||||
if (calculation?.options) _store.$calculation.$options.hydrate(calculation.options);
|
||||
if (calculation?.filters) _store.$calculation.$options.hydrate(calculation.filters);
|
||||
|
||||
if (tables.insurance) {
|
||||
if (tables?.insurance) {
|
||||
_store.$tables.insurance.hydrate({
|
||||
values: tables.insurance.values,
|
||||
options: tables.insurance.options,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import type * as Insurance from 'Components/Calculation/Form/Insurance/InsuranceTable/types';
|
||||
import * as insuranceTableConfig from 'config/tables/insurance-table';
|
||||
import { mergeWith } from 'lodash';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
@ -12,9 +13,9 @@ export interface InsuranceTableData {
|
||||
|
||||
export default class InsuranceTable {
|
||||
root: RootStore;
|
||||
values: Insurance.Row[] = [];
|
||||
options: Insurance.Options = {};
|
||||
statuses: Insurance.RowStatuses[] = [];
|
||||
values: Insurance.Row[] = insuranceTableConfig.defaultRows;
|
||||
options: Insurance.Options = insuranceTableConfig.defaultOptions;
|
||||
statuses: Insurance.RowStatuses[] = insuranceTableConfig.defaultStatuses;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
this.root = rootStore;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { NormalizedCacheObject } from '@apollo/client';
|
||||
import type { User } from 'services/user/types';
|
||||
import type { CalculationOptions } from 'stores/calculation/options/types';
|
||||
import type { CalculationFilters, CalculationOptions } from 'stores/calculation/options/types';
|
||||
import type { CalculationStatuses } from 'stores/calculation/statuses/types';
|
||||
import type { CalculationValues } from 'stores/calculation/values/types';
|
||||
import type { InsuranceTableData } from 'stores/tables/insurance';
|
||||
@ -10,10 +10,11 @@ export interface BasePageProps {
|
||||
initialApolloState: NormalizedCacheObject;
|
||||
calculation?: {
|
||||
values: CalculationValues;
|
||||
statuses?: CalculationStatuses;
|
||||
options?: CalculationOptions;
|
||||
statuses: CalculationStatuses;
|
||||
options: CalculationOptions;
|
||||
filters: Partial<CalculationFilters>;
|
||||
};
|
||||
tables: {
|
||||
tables?: {
|
||||
insurance: InsuranceTableData;
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user