mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
refactor(FE-114): update input handling for vaccination stock, mortality count, and feed stock with improved parsing and formatting
This commit is contained in:
@@ -511,7 +511,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
const handleVaccinationStockChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseFloat(e.target.value.replace(/[^\d,.-]/g, '').replace(/,/g, '')) || 0;
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
formik.setFieldValue(`vaccination.${idx}.used_stock`, value);
|
||||
},
|
||||
[formik]
|
||||
@@ -519,7 +519,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
const handleMortalityCountChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseFloat(e.target.value.replace(/[^\d,.-]/g, '').replace(/,/g, '')) || 0;
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
formik.setFieldValue(`mortality.${idx}.count`, value);
|
||||
},
|
||||
[formik]
|
||||
@@ -596,6 +596,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
setSelectedMortality([]);
|
||||
};
|
||||
|
||||
const handleFeedStockChangeWrapper = useCallback(
|
||||
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value.replace(/[^\d.-]/g, '')) || 0;
|
||||
formik.setFieldValue(`feed_data.${idx}.feed_stock`, value);
|
||||
},
|
||||
[formik]
|
||||
);
|
||||
|
||||
// HELPER FUNCTIONS
|
||||
const isRepeaterInputError = <
|
||||
T extends 'feed_data' | 'body_weight' | 'vaccination' | 'mortality',
|
||||
@@ -916,7 +924,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
value={
|
||||
feed.feed_qty === '' || feed.feed_qty === undefined
|
||||
? ''
|
||||
: String(feed.feed_qty)
|
||||
: Number(feed.feed_qty).toLocaleString('en-US')
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
@@ -932,11 +940,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
required
|
||||
name={`feed_data.${idx}.feed_stock`}
|
||||
value={feed.feed_stock}
|
||||
onChange={formik.handleChange}
|
||||
onChange={handleFeedStockChangeWrapper(idx)}
|
||||
onBlur={formik.handleBlur}
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
isError={
|
||||
isRepeaterInputError('feed_data', 'feed_stock', idx)
|
||||
.isError
|
||||
@@ -1422,7 +1432,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
vaccine.total_stock === '' ||
|
||||
vaccine.total_stock === undefined
|
||||
? ''
|
||||
: String(vaccine.total_stock)
|
||||
: Number(vaccine.total_stock).toLocaleString('en-US')
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
@@ -1443,6 +1453,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
isError={
|
||||
isRepeaterInputError(
|
||||
'vaccination',
|
||||
@@ -1651,6 +1663,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
maskType='number'
|
||||
decimals={0}
|
||||
min={0}
|
||||
thousandSeparator=','
|
||||
decimalSeparator=''
|
||||
isError={
|
||||
isRepeaterInputError('mortality', 'count', idx)
|
||||
.isError
|
||||
|
||||
Reference in New Issue
Block a user