recalc: fix validation (debounce effect)
This commit is contained in:
parent
72b5af9b41
commit
09832eec23
@ -45,16 +45,18 @@ export async function getKPData({
|
||||
quote?.evo_nds_in_price_supplier_currency ?? defaultValues.VATInLeaseObjectPrice,
|
||||
addEquipmentPrice: quote?.evo_equip_price ?? defaultValues.addEquipmentPrice,
|
||||
comissionPerc: quote?.evo_comission_perc ?? defaultValues.comissionPerc,
|
||||
// supplierDiscountRub: quote?.evo_discount_supplier_currency ?? defaultValues.supplierDiscountRub,
|
||||
// comissionRub: quote?.evo_comission_rub ,
|
||||
comissionRub: quote?.evo_comission_rub ?? defaultValues.comissionRub,
|
||||
firstPaymentPerc: quote?.evo_first_payment_perc ?? defaultValues.firstPaymentPerc,
|
||||
// lastPaymentRub: quote?.evo_last_payment_rub ,
|
||||
lastPaymentPerc: quote?.evo_last_payment_perc ?? defaultValues.lastPaymentPerc,
|
||||
lastPaymentRub: quote?.evo_last_payment_rub ?? defaultValues.lastPaymentRub,
|
||||
lastPaymentRule: quote?.evo_last_payment_calc,
|
||||
leaseObjectPrice: quote?.evo_supplier_currency_price ?? defaultValues.leaseObjectPrice,
|
||||
// leaseObjectPriceWthtVAT: quote?.evo_price_without_nds_supplier_currency ,
|
||||
leaseObjectPriceWthtVAT:
|
||||
quote?.evo_price_without_nds_supplier_currency ?? defaultValues.leaseObjectPriceWthtVAT,
|
||||
supplierCurrency: quote?.evo_transactioncurrencyid ?? defaultValues.supplierCurrency,
|
||||
supplierDiscountPerc: quote?.evo_discount_perc ?? defaultValues.supplierDiscountPerc,
|
||||
supplierDiscountRub:
|
||||
quote?.evo_discount_supplier_currency ?? defaultValues.supplierDiscountRub,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import type { ProcessContext } from '../types';
|
||||
import { createValidationSchema } from './validation';
|
||||
import { makeDisposable, normalizeOptions } from '@/../../packages/tools';
|
||||
import type { Elements } from '@/Components/Calculation/config/map/values';
|
||||
import { selectRequirementTelematic } from '@/config/default-options';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
@ -10,6 +9,7 @@ import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { reaction } from 'mobx';
|
||||
import { uid } from 'radash';
|
||||
import { debouncedReaction, makeDisposable, normalizeOptions } from 'tools';
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
@ -229,7 +229,7 @@ export function validation(context: ProcessContext) {
|
||||
const validationSchema = createValidationSchema(context);
|
||||
|
||||
const helper = new ValidationHelper();
|
||||
reaction(
|
||||
debouncedReaction(
|
||||
() =>
|
||||
$calculation.$values.getValues(Object.keys(validationSchema._def.schema.shape) as Values[]),
|
||||
async (values) => {
|
||||
@ -246,8 +246,6 @@ export function validation(context: ProcessContext) {
|
||||
helper.removeErrors();
|
||||
}
|
||||
},
|
||||
{
|
||||
delay: 100,
|
||||
}
|
||||
{ delay: 1, wait: 1000 }
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import type { IReactionDisposer } from 'mobx';
|
||||
import { autorun } from 'mobx';
|
||||
import type { IReactionDisposer, IReactionOptions, IReactionPublic } from 'mobx';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import { debounce } from 'radash';
|
||||
|
||||
export function makeDisposable(
|
||||
createReaction: () => IReactionDisposer,
|
||||
@ -20,3 +21,17 @@ export function makeDisposable(
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function debouncedReaction<T, FireImmediately extends boolean = false>(
|
||||
expression: (r: IReactionPublic) => T,
|
||||
effect: (
|
||||
arg: T,
|
||||
prev: FireImmediately extends true ? T | undefined : T,
|
||||
r: IReactionPublic
|
||||
) => void,
|
||||
{ wait, ...reactionOpts }: IReactionOptions<T, FireImmediately> & { wait: number }
|
||||
): IReactionDisposer {
|
||||
const debouncedEffect = debounce({ delay: wait }, effect);
|
||||
|
||||
return reaction(expression, debouncedEffect, reactionOpts);
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
"eslint-config-custom": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"mobx": "^6.8.0"
|
||||
"mobx": "^6.8.0",
|
||||
"radash": "^10.8.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -7829,6 +7829,11 @@ radash@^10.7.0:
|
||||
resolved "https://registry.yarnpkg.com/radash/-/radash-10.7.0.tgz#aaa164f9697a440d848b88323d51d1bc4f39608a"
|
||||
integrity sha512-dz5NUcGnvn080kKJnyPtqVnP4MWoiwp5qQhEQFK/qMJxCjffQd8tMR4cybxy6y5hupYa5UkSlJRSRY2F7GPBxQ==
|
||||
|
||||
radash@^10.8.1:
|
||||
version "10.8.1"
|
||||
resolved "https://registry.yarnpkg.com/radash/-/radash-10.8.1.tgz#7a49fa1ec07381dba9174ddadf83401e1db293f9"
|
||||
integrity sha512-NzYo3XgM9Tzjf5iFPIMG2l5+LSOCi2H7Axe3Ry/1PrhlvuqxUoiLsmcTBtw4CfKtzy5Fzo79STiEj9JZWMfDQg==
|
||||
|
||||
rambda@^7.1.0:
|
||||
version "7.4.0"
|
||||
resolved "https://registry.yarnpkg.com/rambda/-/rambda-7.4.0.tgz#61ec9de31d3dd6affe804de3bae04a5b818781e5"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user