mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
fix(FE): adding standard fcr to growing production standard
This commit is contained in:
+1
-1
@@ -32,7 +32,7 @@ const GrowingRepeaterFormSchema = Yup.object({
|
|||||||
target_hen_house_production: Yup.number().optional(),
|
target_hen_house_production: Yup.number().optional(),
|
||||||
target_egg_weight: Yup.number().optional(),
|
target_egg_weight: Yup.number().optional(),
|
||||||
target_egg_mass: Yup.number().optional(),
|
target_egg_mass: Yup.number().optional(),
|
||||||
standard_fcr: Yup.number().optional(),
|
standard_fcr: Yup.number().required('Wajib diisi!'),
|
||||||
}).optional(),
|
}).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+62
-42
@@ -386,14 +386,6 @@ const ProductionStandardForm = ({
|
|||||||
`${row.original.production_standard_details?.target_egg_mass} kg`,
|
`${row.original.production_standard_details?.target_egg_mass} kg`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
header: 'FCR',
|
|
||||||
accessorFn: (row) =>
|
|
||||||
row.production_standard_details?.standard_fcr,
|
|
||||||
cell: ({ row }) =>
|
|
||||||
`${row.original.production_standard_details?.standard_fcr} g`,
|
|
||||||
enableSorting: false,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
@@ -468,6 +460,13 @@ const ProductionStandardForm = ({
|
|||||||
return [
|
return [
|
||||||
...baseColumns,
|
...baseColumns,
|
||||||
...productionColumns,
|
...productionColumns,
|
||||||
|
{
|
||||||
|
header: 'FCR',
|
||||||
|
accessorFn: (row) => row.production_standard_details?.standard_fcr,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.standard_fcr} g`,
|
||||||
|
enableSorting: false,
|
||||||
|
},
|
||||||
...uniformityColumns,
|
...uniformityColumns,
|
||||||
...(formType !== 'detail' ? [actionColumn] : []),
|
...(formType !== 'detail' ? [actionColumn] : []),
|
||||||
];
|
];
|
||||||
@@ -753,24 +752,46 @@ const ProductionStandardForm = ({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// For GROWING category, clear production_standard_details errors and set default values
|
// For GROWING category, clear production_standard_details errors and set default values
|
||||||
|
// but preserve standard_fcr since it's used for both LAYING and GROWING
|
||||||
if (formik.values.project_category === 'GROWING') {
|
if (formik.values.project_category === 'GROWING') {
|
||||||
// Set default values for production_standard_details
|
// Set default values for production_standard_details, preserving standard_fcr
|
||||||
formik.values.details?.forEach((detail) => {
|
formik.values.details?.forEach((detail) => {
|
||||||
detail.production_standard_details = {
|
detail.production_standard_details = {
|
||||||
target_hen_day_production: 0,
|
target_hen_day_production: 0,
|
||||||
target_hen_house_production: 0,
|
target_hen_house_production: 0,
|
||||||
target_egg_weight: 0,
|
target_egg_weight: 0,
|
||||||
target_egg_mass: 0,
|
target_egg_mass: 0,
|
||||||
standard_fcr: 0,
|
standard_fcr:
|
||||||
|
detail.production_standard_details?.standard_fcr || 0,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clear any errors related to production_standard_details
|
// Clear errors only for LAYING-specific fields in production_standard_details
|
||||||
|
// Preserve standard_fcr error since it's required for both categories
|
||||||
const currentErrors = { ...formik.errors };
|
const currentErrors = { ...formik.errors };
|
||||||
if (currentErrors.details && Array.isArray(currentErrors.details)) {
|
if (currentErrors.details && Array.isArray(currentErrors.details)) {
|
||||||
const cleanedDetails = currentErrors.details
|
const cleanedDetails = currentErrors.details
|
||||||
.map((detailError) => {
|
.map((detailError) => {
|
||||||
if (detailError && typeof detailError === 'object') {
|
if (detailError && typeof detailError === 'object') {
|
||||||
|
const prodDetails = (
|
||||||
|
detailError as {
|
||||||
|
production_standard_details?: ProductionDetailsErrors;
|
||||||
|
}
|
||||||
|
).production_standard_details;
|
||||||
|
|
||||||
|
// If there's standard_fcr error, preserve it
|
||||||
|
if (prodDetails && prodDetails.standard_fcr) {
|
||||||
|
const { production_standard_details, ...rest } =
|
||||||
|
detailError;
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
production_standard_details: {
|
||||||
|
standard_fcr: prodDetails.standard_fcr,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, remove entire production_standard_details errors
|
||||||
const { production_standard_details, ...rest } = detailError;
|
const { production_standard_details, ...rest } = detailError;
|
||||||
return Object.keys(rest).length > 0 ? rest : undefined;
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
||||||
}
|
}
|
||||||
@@ -896,7 +917,7 @@ const ProductionStandardForm = ({
|
|||||||
gridTemplateColumns:
|
gridTemplateColumns:
|
||||||
formik.values.project_category === 'LAYING'
|
formik.values.project_category === 'LAYING'
|
||||||
? 'repeat(10, minmax(auto, 1fr)) minmax(auto, auto)'
|
? 'repeat(10, minmax(auto, 1fr)) minmax(auto, auto)'
|
||||||
: 'repeat(4, minmax(auto, 1fr)) minmax(auto, auto)',
|
: 'repeat(5, minmax(auto, 1fr)) minmax(auto, auto)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
@@ -1042,39 +1063,38 @@ const ProductionStandardForm = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<NumberInput
|
</>
|
||||||
name='production_standard_details.standard_fcr'
|
)}
|
||||||
label='FCR'
|
<NumberInput
|
||||||
placeholder='1'
|
name='production_standard_details.standard_fcr'
|
||||||
value={
|
label='FCR'
|
||||||
repeaterFormik.values
|
placeholder='1'
|
||||||
.production_standard_details?.standard_fcr
|
value={
|
||||||
}
|
repeaterFormik.values.production_standard_details
|
||||||
onChange={repeaterFormik.handleChange}
|
?.standard_fcr
|
||||||
onBlur={repeaterFormik.handleBlur}
|
}
|
||||||
bottomLabel='Gram (g)'
|
onChange={repeaterFormik.handleChange}
|
||||||
errorMessage={getProductionDetailsError(
|
onBlur={repeaterFormik.handleBlur}
|
||||||
|
bottomLabel='Gram (g)'
|
||||||
|
errorMessage={getProductionDetailsError(
|
||||||
|
repeaterFormik.errors.production_standard_details,
|
||||||
|
'standard_fcr'
|
||||||
|
)}
|
||||||
|
isError={
|
||||||
|
Boolean(
|
||||||
|
getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
'standard_fcr'
|
'standard_fcr'
|
||||||
)}
|
)
|
||||||
isError={
|
) &&
|
||||||
Boolean(
|
getProductionDetailsTouched(
|
||||||
getProductionDetailsError(
|
repeaterFormik.touched
|
||||||
repeaterFormik.errors
|
.production_standard_details,
|
||||||
.production_standard_details,
|
'standard_fcr'
|
||||||
'standard_fcr'
|
)
|
||||||
)
|
}
|
||||||
) &&
|
/>
|
||||||
getProductionDetailsTouched(
|
|
||||||
repeaterFormik.touched
|
|
||||||
.production_standard_details,
|
|
||||||
'standard_fcr'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<NumberInput
|
<NumberInput
|
||||||
name='production_standard_uniformity_details.target_mean_bw'
|
name='production_standard_uniformity_details.target_mean_bw'
|
||||||
label='Mean BW'
|
label='Mean BW'
|
||||||
|
|||||||
Reference in New Issue
Block a user