mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
feat(FE-114,137): enhance RecordingForm to handle stock usage and depletion total changes with improved input handling
This commit is contained in:
@@ -440,6 +440,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
}, [stockProducts, getProjectFlockLocation()]);
|
||||
|
||||
|
||||
// Handle stock usage amount change
|
||||
const handleStockUsageAmountChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
formik.setFieldValue(`stocks.${idx}.usage_amount`, value);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
|
||||
// Unified Stock remove handlers
|
||||
const removeStock = (idx: number) => {
|
||||
const updatedStocks = formik.values.stocks?.filter((_, i) => i !== idx);
|
||||
@@ -466,6 +475,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
formik.setFieldValue('depletions', newDepletions);
|
||||
};
|
||||
|
||||
// Handle depletion total change
|
||||
const handleDepletionTotalChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
formik.setFieldValue(`depletions.${idx}.total`, value);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
|
||||
const removeDepletion = (idx: number) => {
|
||||
const updatedDepletions = formik.values.depletions?.filter(
|
||||
(_, i) => i !== idx
|
||||
@@ -942,14 +960,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
<NumberInput
|
||||
required
|
||||
name={`stocks.${idx}.usage_amount`}
|
||||
value={stock.usage_amount || 0}
|
||||
onChange={formik.handleChange}
|
||||
value={stock.usage_amount}
|
||||
onChange={handleStockUsageAmountChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
thousandSeparator=','
|
||||
decimalSeparator='.'
|
||||
decimalSeparator=''
|
||||
isError={
|
||||
isRepeaterInputError('stocks', 'usage_amount', idx)
|
||||
.isError
|
||||
@@ -1127,17 +1145,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
<NumberInput
|
||||
required
|
||||
name={`depletions.${idx}.total`}
|
||||
type='number'
|
||||
value={
|
||||
typeof depletion.total === 'number'
|
||||
? depletion.total.toString()
|
||||
: depletion.total
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
value={depletion.total}
|
||||
onChange={handleDepletionTotalChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
isError={
|
||||
isRepeaterInputError('depletions', 'total', idx)
|
||||
.isError
|
||||
|
||||
Reference in New Issue
Block a user