mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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]
|
[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 removeBodyWeight = (idx: number) => {
|
||||||
const updatedBodyWeight = formik.values.body_weight?.filter(
|
const updatedBodyWeight = formik.values.body_weight?.filter(
|
||||||
(_, i) => i !== idx
|
(_, i) => i !== idx
|
||||||
@@ -1422,7 +1438,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
required
|
required
|
||||||
name={`vaccination.${idx}.used_stock`}
|
name={`vaccination.${idx}.used_stock`}
|
||||||
value={vaccine.used_stock}
|
value={vaccine.used_stock}
|
||||||
onChange={formik.handleChange}
|
onChange={handleVaccinationStockChangeWrapper(idx)}
|
||||||
onBlur={formik.handleBlur}
|
onBlur={formik.handleBlur}
|
||||||
maskType='number'
|
maskType='number'
|
||||||
decimals={0}
|
decimals={0}
|
||||||
@@ -1630,7 +1646,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
required
|
required
|
||||||
name={`mortality.${idx}.count`}
|
name={`mortality.${idx}.count`}
|
||||||
value={mortality.count}
|
value={mortality.count}
|
||||||
onChange={formik.handleChange}
|
onChange={handleMortalityCountChangeWrapper(idx)}
|
||||||
onBlur={formik.handleBlur}
|
onBlur={formik.handleBlur}
|
||||||
maskType='number'
|
maskType='number'
|
||||||
decimals={0}
|
decimals={0}
|
||||||
|
|||||||
Reference in New Issue
Block a user