refactor(FE-114): simplify input handling in MovementForm and RecordingForm by removing unnecessary value normalization

This commit is contained in:
rstubryan
2025-10-25 11:26:38 +07:00
parent 6290199074
commit d7ce8c667a
2 changed files with 27 additions and 42 deletions
@@ -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',