mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-114): simplify input handling in MovementForm and RecordingForm by removing unnecessary value normalization
This commit is contained in:
@@ -427,9 +427,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
|
||||
const handleDeliveryCostChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const rawValue = e.target.value.replace(/[^\d,.-]/g, '');
|
||||
const normalizedValue = rawValue.replace(/,/g, '');
|
||||
const value = parseFloat(normalizedValue) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
handleDeliveryCostChange(idx, value);
|
||||
},
|
||||
[handleDeliveryCostChange]
|
||||
@@ -437,9 +435,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
|
||||
const handleDeliveryCostPerItemChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const rawValue = e.target.value.replace(/[^\d,.-]/g, '');
|
||||
const normalizedValue = rawValue.replace(/,/g, '');
|
||||
const value = parseFloat(normalizedValue) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
handleDeliveryCostPerItemChange(idx, value);
|
||||
},
|
||||
[handleDeliveryCostPerItemChange]
|
||||
@@ -1389,9 +1385,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
value={delivery.delivery_cost || ''}
|
||||
onChange={handleDeliveryCostChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='currency'
|
||||
decimals={0}
|
||||
min={0}
|
||||
decimalScale={0}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
{...isRepeaterInputError(
|
||||
'deliveries',
|
||||
'delivery_cost',
|
||||
@@ -1411,9 +1408,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
value={delivery.delivery_cost_per_item || ''}
|
||||
onChange={handleDeliveryCostPerItemChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='currency'
|
||||
decimals={0}
|
||||
min={0}
|
||||
decimalScale={0}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
{...isRepeaterInputError(
|
||||
'deliveries',
|
||||
'delivery_cost_per_item',
|
||||
|
||||
@@ -494,16 +494,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
};
|
||||
|
||||
const handleWeightChangeWrapper = (idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const rawValue = e.target.value.replace(/[^\d,.-]/g, '');
|
||||
const normalizedValue = rawValue.replace(/,/g, '');
|
||||
const value = parseFloat(normalizedValue) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
handleWeightChange(idx, value);
|
||||
};
|
||||
|
||||
const handleQtyChangeWrapper = (idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const rawValue = e.target.value.replace(/[^\d,.-]/g, '');
|
||||
const normalizedValue = rawValue.replace(/,/g, '');
|
||||
const value = parseFloat(normalizedValue) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
handleQtyChange(idx, value);
|
||||
};
|
||||
|
||||
@@ -511,9 +507,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
setEditingAverageIndex(idx);
|
||||
setManuallyEditedRows(prev => new Set(prev).add(idx));
|
||||
|
||||
const rawValue = e.target.value.replace(/[^\d,.-]/g, '');
|
||||
const normalizedValue = rawValue.replace(/,/g, '');
|
||||
const value = parseFloat(normalizedValue) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
handleAverageWeightChange(idx, value);
|
||||
};
|
||||
|
||||
@@ -551,7 +545,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
const handleStockUsageAmountChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
formik.setFieldValue(`stocks.${idx}.usage_amount`, value);
|
||||
},
|
||||
[formik]
|
||||
@@ -584,7 +578,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
const handleDepletionTotalChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
const value = parseFloat(e.target.value) || 0;
|
||||
formik.setFieldValue(`depletions.${idx}.total`, value);
|
||||
},
|
||||
[formik]
|
||||
@@ -801,10 +795,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
value={bw.weight}
|
||||
onChange={handleWeightChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='weight'
|
||||
weightUnit='gram'
|
||||
decimals={2}
|
||||
min={0}
|
||||
decimalScale={2}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
isError={
|
||||
@@ -828,9 +820,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
value={bw.qty}
|
||||
onChange={handleQtyChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
decimalScale={0}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
isError={
|
||||
@@ -856,10 +847,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
handleAverageWeightBlur(idx);
|
||||
formik.handleBlur(e);
|
||||
}}
|
||||
maskType='weight'
|
||||
weightUnit='gram'
|
||||
decimals={2}
|
||||
min={0}
|
||||
decimalScale={2}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
isError={
|
||||
@@ -1063,11 +1052,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
value={stock.usage_amount}
|
||||
onChange={handleStockUsageAmountChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
decimalScale={0}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
decimalSeparator='.'
|
||||
isError={
|
||||
isRepeaterInputError('stocks', 'usage_amount', idx)
|
||||
.isError || Boolean(getStockUsageError(idx))
|
||||
@@ -1255,11 +1243,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
value={depletion.total}
|
||||
onChange={handleDepletionTotalChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
decimalScale={0}
|
||||
allowNegative={false}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
decimalSeparator='.'
|
||||
isError={
|
||||
isRepeaterInputError('depletions', 'total', idx)
|
||||
.isError
|
||||
|
||||
Reference in New Issue
Block a user