mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
refactor(FE-114): implement custom handlers for vaccination stock and mortality count input parsing
This commit is contained in:
@@ -509,6 +509,22 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
[handleAverageWeightChange]
|
||||
);
|
||||
|
||||
const handleVaccinationStockChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseFloat(e.target.value.replace(/[^\d,.-]/g, '').replace(/,/g, '')) || 0;
|
||||
formik.setFieldValue(`vaccination.${idx}.used_stock`, value);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
|
||||
const handleMortalityCountChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseFloat(e.target.value.replace(/[^\d,.-]/g, '').replace(/,/g, '')) || 0;
|
||||
formik.setFieldValue(`mortality.${idx}.count`, value);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
|
||||
const removeBodyWeight = (idx: number) => {
|
||||
const updatedBodyWeight = formik.values.body_weight?.filter(
|
||||
(_, i) => i !== idx
|
||||
@@ -1422,7 +1438,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
required
|
||||
name={`vaccination.${idx}.used_stock`}
|
||||
value={vaccine.used_stock}
|
||||
onChange={formik.handleChange}
|
||||
onChange={handleVaccinationStockChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
@@ -1630,7 +1646,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
required
|
||||
name={`mortality.${idx}.count`}
|
||||
value={mortality.count}
|
||||
onChange={formik.handleChange}
|
||||
onChange={handleMortalityCountChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
|
||||
Reference in New Issue
Block a user