From a53600fb85b522474e3f59c431239bb74fbcbb3e Mon Sep 17 00:00:00 2001 From: merelendor Date: Tue, 27 Sep 2022 19:49:07 +0300 Subject: [PATCH] hotfix for forms submission by enter key on calculations form, possible fix for double calculation call --- .../change/components/Options/index.js | 83 ++++++++++++------- .../change/components/VariantsList/index.js | 10 ++- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/pages/contract/change/components/Options/index.js b/pages/contract/change/components/Options/index.js index 4a0c01c..d2440e7 100644 --- a/pages/contract/change/components/Options/index.js +++ b/pages/contract/change/components/Options/index.js @@ -323,6 +323,15 @@ class SumSelector extends React.Component } } + _handle_onKeyDown = (event) => + { + if(event.keyCode === 13) + { + event.preventDefault(); + this.props.onSubmit(event); + } + } + _handle_onMin = () => { const { onOption } = this.props; @@ -366,7 +375,7 @@ class SumSelector extends React.Component
- + от { numeral(min).format(' ., ') } ₽ до { numeral(max).format(' ., ') } ₽
@@ -446,6 +455,15 @@ class InsurancePriceSelector extends React.Component //} } + _handle_onKeyDown = (event) => + { + if(event.keyCode === 13) + { + event.preventDefault(); + this.props.onSubmit(event); + } + } + _handle_onMin = () => { const { min } = this.state; @@ -479,7 +497,7 @@ class InsurancePriceSelector extends React.Component <>{ numeral(value).format(' ., ') } ₽ ) : ( <> - + от { numeral(min).format(' ., ') } ₽ до { numeral(max).format(' ., ') } ₽ @@ -622,37 +640,39 @@ export default class Options extends React.Component _handle_onCalculate = (event) => { + event.preventDefault(); + event.stopPropagation(); + const { sending, number_paydate, period_new, fix_last_payment_available, date_offset_type, sum, insurance_price_result, datefrom, } = this.state; const { number, options, variants, onCalculate } = this.props; - event.preventDefault(); - console.log(this.props); - - const selected = { - number_planpayment: options.number_planpayment.value, - }; - - if(number_paydate !== null) { selected.number_paydate = moment(number_paydate).format(); } - if(period_new !== null) { selected.period_new = period_new; } - //if(fix_last_payment_available !== null) { selected.fix_last_payment_available = fix_last_payment_available; } - if(date_offset_type !== null) { selected.date_offset_type = date_offset_type; } - if(sum !== null) { selected.sum = sum; } - if(insurance_price_result !== null) { selected.insurance_price_result = insurance_price_result; } - //if(early_redemption_change !== null) { selected.early_redemption_change = early_redemption_change; } - if(datefrom !== null) { selected.datefrom = moment(datefrom).format(); } - if(!sending) { - const v = {}; - for(let i in variants.types) { v[ variants.types[i].name ] = variants.types[i].value; } - const payload = { - ...{ contract_number: number }, - ...v, - ...selected - }; - this.setState({ sending: true, }, () => { + console.log("_handle_onCalculate ?"); + + const selected = { + number_planpayment: options.number_planpayment.value, + }; + + if(number_paydate !== null) { selected.number_paydate = moment(number_paydate).format(); } + if(period_new !== null) { selected.period_new = period_new; } + //if(fix_last_payment_available !== null) { selected.fix_last_payment_available = fix_last_payment_available; } + if(date_offset_type !== null) { selected.date_offset_type = date_offset_type; } + if(sum !== null) { selected.sum = sum; } + if(insurance_price_result !== null) { selected.insurance_price_result = insurance_price_result; } + //if(early_redemption_change !== null) { selected.early_redemption_change = early_redemption_change; } + if(datefrom !== null) { selected.datefrom = moment(datefrom).format(); } + + const v = {}; + for(let i in variants.types) { v[ variants.types[i].name ] = variants.types[i].value; } + const payload = { + ...{ contract_number: number }, + ...v, + ...selected + }; + getContractGraphicChangeCalculate(payload) .then((calculation) => { @@ -665,7 +685,7 @@ export default class Options extends React.Component alert("К сожалению, при расчёте возникла ошибка.\n\nДля расчёта вариантов изменения графика обратитесь, пожалуйста, в Службу клиентского сервиса по адресу электронной почты clint@evoleasing.ru или по телефону Горячей линии 8 800 333 75 75."); }); }); - }); + }); } } @@ -731,6 +751,7 @@ export default class Options extends React.Component { const { loading, sending, } = this.state; const { variants, options } = this.props; + /*this._checkAllowCalculate() ? this._handle_onCalculate : {}*/ return (
@@ -741,7 +762,7 @@ export default class Options extends React.Component
) : ( -
+ { options !== undefined && options !== null && options.number_paydate !== undefined && options.number_paydate !== null && options.number_paydate.visible && ( ) } @@ -755,17 +776,17 @@ export default class Options extends React.Component ) } { options !== undefined && options !== null && options.sum !== undefined && options.sum !== null && options.sum.visible && ( - + ) } { options !== undefined && options !== null && options.insurance_price_result !== undefined && options.insurance_price_result !== null && options.insurance_price_result.visible && ( - + ) } { options !== undefined && options !== null && options.datefrom !== undefined && options.datefrom !== null && options.datefrom.visible && ( ) }
- - )} + + ) }
{ loading && (