fix: disable tables callbacks during loadKp
This commit is contained in:
parent
ade824355f
commit
f8797c287f
@ -45,7 +45,7 @@
|
||||
"styled-system": "^5.1.5",
|
||||
"ts-loader": "^8.0.2",
|
||||
"typescript": "3.9.7",
|
||||
"use-debounce": "^3.4.3",
|
||||
"use-debounce": "^5.1.0",
|
||||
"uuid": "^8.3.1",
|
||||
"validator": "^13.1.1"
|
||||
},
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import { DEFAULT_DEBOUNCE_DELAY } from 'client/constants/debounce';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useDebounce } from 'use-debounce/lib';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
import { useStores } from '../useStores';
|
||||
|
||||
export const useComputedValue = ({ computedValueName }) => {
|
||||
@ -14,7 +15,6 @@ export const useComputedValue = ({ computedValueName }) => {
|
||||
export const useStoreValue = ({ valueName }) => {
|
||||
const { calculationStore } = useStores();
|
||||
const [currentValue, setCurrentValue] = useState(undefined);
|
||||
const [debouncedValue] = useDebounce(currentValue, DEFAULT_DEBOUNCE_DELAY);
|
||||
|
||||
const sourceValue = calculationStore.values[valueName];
|
||||
|
||||
@ -26,20 +26,22 @@ export const useStoreValue = ({ valueName }) => {
|
||||
}, [sourceValue]);
|
||||
|
||||
// set value to store
|
||||
const debounced = useDebouncedCallback(
|
||||
(valueName, value) => calculationStore.setValue(valueName, value),
|
||||
DEFAULT_DEBOUNCE_DELAY,
|
||||
);
|
||||
useEffect(() => {
|
||||
if (debouncedValue !== undefined) {
|
||||
calculationStore.setValue(valueName, debouncedValue);
|
||||
}
|
||||
}, [debouncedValue]);
|
||||
debounced.callback(valueName, currentValue);
|
||||
}, [currentValue]);
|
||||
|
||||
return { value: currentValue, setCurrentValue, debouncedValue };
|
||||
return { value: currentValue, setCurrentValue };
|
||||
};
|
||||
|
||||
export const useTableValue = ({ tableName, rowIndex, propName }) => {
|
||||
const { calculationStore, calculationProcess } = useStores();
|
||||
const [currentValue, setCurrentValue] = useState(undefined);
|
||||
const [debouncedValue] = useDebounce(currentValue, DEFAULT_DEBOUNCE_DELAY);
|
||||
|
||||
//get row value from store
|
||||
const sourceValue =
|
||||
calculationStore.tables[tableName].rows[rowIndex][propName].value;
|
||||
useEffect(() => {
|
||||
@ -48,33 +50,58 @@ export const useTableValue = ({ tableName, rowIndex, propName }) => {
|
||||
}
|
||||
}, [sourceValue]);
|
||||
|
||||
const debouncedSetTableRow = useDebouncedCallback(
|
||||
(tableName, rowIndex, rows) => {
|
||||
calculationStore.setTableRow(tableName, rowIndex)(rows);
|
||||
},
|
||||
DEFAULT_DEBOUNCE_DELAY,
|
||||
);
|
||||
|
||||
//set row value to store
|
||||
useEffect(() => {
|
||||
if (debouncedValue !== undefined)
|
||||
calculationStore.setTableRow(
|
||||
tableName,
|
||||
rowIndex,
|
||||
)({
|
||||
if (currentValue !== undefined)
|
||||
debouncedSetTableRow.callback(tableName, rowIndex, {
|
||||
[propName]: {
|
||||
value: debouncedValue,
|
||||
value: currentValue,
|
||||
},
|
||||
});
|
||||
}, [debouncedValue]);
|
||||
}, [currentValue]);
|
||||
|
||||
//use cell callback (only during default process)
|
||||
const debouncedCellCallback = useDebouncedCallback(
|
||||
(
|
||||
callback,
|
||||
calculationStore,
|
||||
calculationProcess,
|
||||
tableName,
|
||||
rowIndex,
|
||||
value,
|
||||
) => {
|
||||
callback({
|
||||
calculationStore,
|
||||
calculationProcess,
|
||||
tableName,
|
||||
rowIndex,
|
||||
value,
|
||||
});
|
||||
},
|
||||
DEFAULT_DEBOUNCE_DELAY,
|
||||
);
|
||||
const cellCallBack =
|
||||
calculationStore.tables[tableName].callbacks &&
|
||||
calculationStore.tables[tableName].callbacks[propName];
|
||||
|
||||
useEffect(() => {
|
||||
if (cellCallBack) {
|
||||
cellCallBack(
|
||||
if (cellCallBack && calculationProcess.process === Process.Default)
|
||||
debouncedCellCallback.callback(
|
||||
cellCallBack,
|
||||
calculationStore,
|
||||
calculationProcess,
|
||||
tableName,
|
||||
rowIndex,
|
||||
debouncedValue,
|
||||
currentValue,
|
||||
);
|
||||
}
|
||||
}, [debouncedValue, cellCallBack]);
|
||||
}, [currentValue]);
|
||||
|
||||
return { value: currentValue, setCurrentValue, debouncedValue };
|
||||
return { value: currentValue, setCurrentValue };
|
||||
};
|
||||
|
||||
@ -324,11 +324,17 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
|
||||
insTerm: { value: quote.evo_insurance_period },
|
||||
},
|
||||
{
|
||||
insuranceCompany: {
|
||||
value: quote.evo_kasko_accountid,
|
||||
},
|
||||
insured: { value: quote.evo_kasko_payer },
|
||||
insCost: { value: quote.evo_dgo_price },
|
||||
insTerm: { value: quote.evo_insurance_period },
|
||||
},
|
||||
{
|
||||
insuranceCompany: {
|
||||
value: quote.evo_kasko_accountid,
|
||||
},
|
||||
insured: { value: quote.evo_kasko_payer },
|
||||
insCost: { value: quote.evo_ns_price },
|
||||
insTerm: { value: quote.evo_insurance_period },
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { ITable } from 'core/types/Calculation/Store/tables';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
|
||||
@ -129,10 +128,7 @@ const tableInsurance: ITable = {
|
||||
],
|
||||
},
|
||||
callbacks: {
|
||||
insCost: (calculationStore, calculationProcess, tableName, rowIndex) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
insCost: ({ calculationStore, tableName, rowIndex }) => {
|
||||
if (
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
|
||||
@ -225,10 +221,7 @@ const tableInsurance: ITable = {
|
||||
}
|
||||
},
|
||||
|
||||
insured: (calculationStore, calculationProcess, tableName, rowIndex) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
insured: ({ calculationStore, tableName, rowIndex }) => {
|
||||
if (
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
|
||||
@ -260,10 +253,7 @@ const tableInsurance: ITable = {
|
||||
}
|
||||
},
|
||||
|
||||
insTerm: (calculationStore, calculationProcess, tableName, rowIndex) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
insTerm: ({ calculationStore, tableName, rowIndex }) => {
|
||||
if (
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
|
||||
@ -294,15 +284,7 @@ const tableInsurance: ITable = {
|
||||
});
|
||||
}
|
||||
},
|
||||
insuranceCompany: (
|
||||
calculationStore,
|
||||
calculationProcess,
|
||||
tableName,
|
||||
rowIndex,
|
||||
) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
insuranceCompany: ({ calculationStore, tableName, rowIndex }) => {
|
||||
if (
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
|
||||
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { ITable } from 'core/types/Calculation/Store/tables';
|
||||
import { toJS } from 'mobx';
|
||||
|
||||
@ -9,16 +8,12 @@ const tablePayments: ITable = {
|
||||
// },
|
||||
],
|
||||
callbacks: {
|
||||
paymentRelation: (
|
||||
paymentRelation: ({
|
||||
calculationStore,
|
||||
calculationProcess,
|
||||
tableName,
|
||||
rowIndex,
|
||||
value,
|
||||
) => {
|
||||
if (calculationProcess.process === Process.LoadKp) {
|
||||
return;
|
||||
}
|
||||
}) => {
|
||||
const { graphType } = calculationStore.values;
|
||||
if (graphType === 100000001) {
|
||||
if (
|
||||
|
||||
@ -18,13 +18,13 @@ export type TableValuesNames =
|
||||
| 'ndsCompensation'
|
||||
| 'redemptionAmount';
|
||||
|
||||
export type TCellCallback = (
|
||||
calculationStore: ICalculationStore,
|
||||
calculationProcess: TCalculationProcess,
|
||||
tableName: TableNames,
|
||||
rowIndex: number,
|
||||
value: any,
|
||||
) => void;
|
||||
export type TCellCallback = (props: {
|
||||
calculationStore: ICalculationStore;
|
||||
calculationProcess: TCalculationProcess;
|
||||
tableName: TableNames;
|
||||
rowIndex: number;
|
||||
value: any;
|
||||
}) => void;
|
||||
|
||||
export interface ITableCell {
|
||||
value?: any;
|
||||
|
||||
Reference in New Issue
Block a user