mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
fix(FE): fixing error message on submit and fixing ui
This commit is contained in:
+15
-19
@@ -2,34 +2,30 @@ import * as Yup from 'yup';
|
|||||||
|
|
||||||
// Schema for LAYING category (production_standard_details is required)
|
// Schema for LAYING category (production_standard_details is required)
|
||||||
const LayingRepeaterFormSchema = Yup.object({
|
const LayingRepeaterFormSchema = Yup.object({
|
||||||
week: Yup.number().required('Minggu wajib diisi!'),
|
week: Yup.number().required('Wajib diisi!'),
|
||||||
production_standard_uniformity_details: Yup.object({
|
production_standard_uniformity_details: Yup.object({
|
||||||
target_mean_bw: Yup.number().required('Berat rata-rata wajib diisi!'),
|
target_mean_bw: Yup.number().required('Wajib diisi!'),
|
||||||
max_depletion: Yup.number().required('Maksimal depletion wajib diisi!'),
|
max_depletion: Yup.number().required('Wajib diisi!'),
|
||||||
min_uniformity: Yup.number().required('Minimal uniformitas wajib diisi!'),
|
min_uniformity: Yup.number().required('Wajib diisi!'),
|
||||||
feed_intake: Yup.number().required('Pengambilan makanan wajib diisi!'),
|
feed_intake: Yup.number().required('Wajib diisi!'),
|
||||||
}),
|
}),
|
||||||
production_standard_details: Yup.object({
|
production_standard_details: Yup.object({
|
||||||
target_hen_day_production: Yup.number().required(
|
target_hen_day_production: Yup.number().required('Wajib diisi!'),
|
||||||
'Produksi telur per hari wajib diisi!'
|
target_hen_house_production: Yup.number().required('Wajib diisi!'),
|
||||||
),
|
target_egg_weight: Yup.number().required('Wajib diisi!'),
|
||||||
target_hen_house_production: Yup.number().required(
|
target_egg_mass: Yup.number().required('Wajib diisi!'),
|
||||||
'Produksi telur per kandang wajib diisi!'
|
standard_fcr: Yup.number().required('Wajib diisi!'),
|
||||||
),
|
|
||||||
target_egg_weight: Yup.number().required('Berat telur wajib diisi!'),
|
|
||||||
target_egg_mass: Yup.number().required('Massa telur wajib diisi!'),
|
|
||||||
standard_fcr: Yup.number().required('FCR wajib diisi!'),
|
|
||||||
}).required(),
|
}).required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Schema for GROWING category (production_standard_details is optional)
|
// Schema for GROWING category (production_standard_details is optional)
|
||||||
const GrowingRepeaterFormSchema = Yup.object({
|
const GrowingRepeaterFormSchema = Yup.object({
|
||||||
week: Yup.number().required('Minggu wajib diisi!'),
|
week: Yup.number().required('Wajib diisi!'),
|
||||||
production_standard_uniformity_details: Yup.object({
|
production_standard_uniformity_details: Yup.object({
|
||||||
target_mean_bw: Yup.number().required('Berat rata-rata wajib diisi!'),
|
target_mean_bw: Yup.number().required('Wajib diisi!'),
|
||||||
max_depletion: Yup.number().required('Maksimal depletion wajib diisi!'),
|
max_depletion: Yup.number().required('Wajib diisi!'),
|
||||||
min_uniformity: Yup.number().required('Minimal uniformitas wajib diisi!'),
|
min_uniformity: Yup.number().required('Wajib diisi!'),
|
||||||
feed_intake: Yup.number().required('Pengambilan makanan wajib diisi!'),
|
feed_intake: Yup.number().required('Wajib diisi!'),
|
||||||
}),
|
}),
|
||||||
production_standard_details: Yup.object({
|
production_standard_details: Yup.object({
|
||||||
target_hen_day_production: Yup.number().optional(),
|
target_hen_day_production: Yup.number().optional(),
|
||||||
|
|||||||
+86
-45
@@ -344,7 +344,7 @@ const ProductionStandardForm = ({
|
|||||||
const columns = useMemo<ColumnDef<TableRowsType>[]>(() => {
|
const columns = useMemo<ColumnDef<TableRowsType>[]>(() => {
|
||||||
const baseColumns: ColumnDef<TableRowsType>[] = [
|
const baseColumns: ColumnDef<TableRowsType>[] = [
|
||||||
{
|
{
|
||||||
header: 'Minggu',
|
header: 'Week',
|
||||||
accessorKey: 'week',
|
accessorKey: 'week',
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
@@ -358,30 +358,40 @@ const ProductionStandardForm = ({
|
|||||||
header: 'Hen Day',
|
header: 'Hen Day',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_details?.target_hen_day_production,
|
row.production_standard_details?.target_hen_day_production,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.target_hen_day_production}%`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Hen House',
|
header: 'Hen House',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_details?.target_hen_house_production,
|
row.production_standard_details?.target_hen_house_production,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.target_hen_house_production} pc`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Egg Weight',
|
header: 'Egg Weight',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_details?.target_egg_weight,
|
row.production_standard_details?.target_egg_weight,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.target_egg_weight} g`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Egg Mass',
|
header: 'Egg Mass',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_details?.target_egg_mass,
|
row.production_standard_details?.target_egg_mass,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.target_egg_mass} g`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'FCR',
|
header: 'FCR',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_details?.standard_fcr,
|
row.production_standard_details?.standard_fcr,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_details?.standard_fcr} g`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -393,24 +403,32 @@ const ProductionStandardForm = ({
|
|||||||
header: 'Mean BW',
|
header: 'Mean BW',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_uniformity_details?.target_mean_bw,
|
row.production_standard_uniformity_details?.target_mean_bw,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_uniformity_details?.target_mean_bw} g`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Max Depletion',
|
header: 'Max Depletion',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_uniformity_details?.max_depletion,
|
row.production_standard_uniformity_details?.max_depletion,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_uniformity_details?.max_depletion}%`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Min Uniformity',
|
header: 'Min Uniformity',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_uniformity_details?.min_uniformity,
|
row.production_standard_uniformity_details?.min_uniformity,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_uniformity_details?.min_uniformity}%`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Feed Intake',
|
header: 'Feed Intake',
|
||||||
accessorFn: (row) =>
|
accessorFn: (row) =>
|
||||||
row.production_standard_uniformity_details?.feed_intake,
|
row.production_standard_uniformity_details?.feed_intake,
|
||||||
|
cell: ({ row }) =>
|
||||||
|
`${row.original.production_standard_uniformity_details?.feed_intake} g`,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -728,7 +746,52 @@ const ProductionStandardForm = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ===== Formik Error List =====
|
// ===== Formik Error List =====
|
||||||
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(
|
||||||
|
formik,
|
||||||
|
{
|
||||||
|
onBeforeSubmit: (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// For GROWING category, clear production_standard_details errors and set default values
|
||||||
|
if (formik.values.project_category === 'GROWING') {
|
||||||
|
// Set default values for production_standard_details
|
||||||
|
formik.values.details?.forEach((detail) => {
|
||||||
|
detail.production_standard_details = {
|
||||||
|
target_hen_day_production: 0,
|
||||||
|
target_hen_house_production: 0,
|
||||||
|
target_egg_weight: 0,
|
||||||
|
target_egg_mass: 0,
|
||||||
|
standard_fcr: 0,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear any errors related to production_standard_details
|
||||||
|
const currentErrors = { ...formik.errors };
|
||||||
|
if (currentErrors.details && Array.isArray(currentErrors.details)) {
|
||||||
|
const cleanedDetails = currentErrors.details
|
||||||
|
.map((detailError) => {
|
||||||
|
if (detailError && typeof detailError === 'object') {
|
||||||
|
const { production_standard_details, ...rest } = detailError;
|
||||||
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
||||||
|
}
|
||||||
|
return detailError;
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
(error): error is Exclude<typeof error, undefined> =>
|
||||||
|
error !== undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
currentErrors.details = (
|
||||||
|
cleanedDetails.length > 0 ? cleanedDetails : undefined
|
||||||
|
) as typeof currentErrors.details;
|
||||||
|
}
|
||||||
|
formik.setErrors(currentErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -821,19 +884,20 @@ const ProductionStandardForm = ({
|
|||||||
key={`row-${row.index}`}
|
key={`row-${row.index}`}
|
||||||
className='sticky bottom-0 bg-base-100 shadow-lg'
|
className='sticky bottom-0 bg-base-100 shadow-lg'
|
||||||
>
|
>
|
||||||
<td colSpan={colSpan} className='p-6'>
|
<td colSpan={colSpan} className='p-2'>
|
||||||
<form
|
<form
|
||||||
className='h-full w-full flex flex-col justify-end'
|
className='h-full w-full flex flex-col justify-end'
|
||||||
onSubmit={repeaterFormik.handleSubmit}
|
onSubmit={repeaterFormik.handleSubmit}
|
||||||
onReset={repeaterFormik.handleReset}
|
onReset={repeaterFormik.handleReset}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className='grid gap-2 items-start w-full'
|
||||||
'grid gap-4 items-start',
|
style={{
|
||||||
formik.values.project_category === 'LAYING'
|
gridTemplateColumns:
|
||||||
? 'grid-cols-10'
|
formik.values.project_category === 'LAYING'
|
||||||
: 'grid-cols-5'
|
? 'repeat(10, minmax(auto, 1fr)) minmax(auto, auto)'
|
||||||
)}
|
: 'repeat(4, minmax(auto, 1fr)) minmax(auto, auto)',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
name='week'
|
name='week'
|
||||||
@@ -862,7 +926,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={<Icon icon='mdi:percent' />}
|
bottomLabel='Persen (%)'
|
||||||
errorMessage={getProductionDetailsError(
|
errorMessage={getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
@@ -894,11 +958,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
bottomLabel='Butir (pc)'
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
|
||||||
Butir
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={getProductionDetailsError(
|
errorMessage={getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
@@ -930,11 +990,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
bottomLabel='Gram (g)'
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
|
||||||
gr
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={getProductionDetailsError(
|
errorMessage={getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
@@ -959,17 +1015,13 @@ const ProductionStandardForm = ({
|
|||||||
name='production_standard_details.target_egg_mass'
|
name='production_standard_details.target_egg_mass'
|
||||||
label='Egg Mass'
|
label='Egg Mass'
|
||||||
placeholder='1'
|
placeholder='1'
|
||||||
|
bottomLabel='Gram (g)'
|
||||||
value={
|
value={
|
||||||
repeaterFormik.values
|
repeaterFormik.values
|
||||||
.production_standard_details?.target_egg_mass
|
.production_standard_details?.target_egg_mass
|
||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
|
||||||
gr
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={getProductionDetailsError(
|
errorMessage={getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
@@ -1000,11 +1052,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
bottomLabel='Gram (g)'
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
|
||||||
gr
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={getProductionDetailsError(
|
errorMessage={getProductionDetailsError(
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_details,
|
.production_standard_details,
|
||||||
@@ -1038,11 +1086,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
bottomLabel='Gram (g)'
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
|
||||||
gr
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={
|
errorMessage={
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_uniformity_details
|
.production_standard_uniformity_details
|
||||||
@@ -1072,7 +1116,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={<Icon icon='mdi:percent' />}
|
bottomLabel='Persen (%)'
|
||||||
errorMessage={
|
errorMessage={
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_uniformity_details
|
.production_standard_uniformity_details
|
||||||
@@ -1102,7 +1146,7 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={<Icon icon='mdi:percent' />}
|
bottomLabel='Persen (%)'
|
||||||
errorMessage={
|
errorMessage={
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_uniformity_details
|
.production_standard_uniformity_details
|
||||||
@@ -1132,11 +1176,8 @@ const ProductionStandardForm = ({
|
|||||||
}
|
}
|
||||||
onChange={repeaterFormik.handleChange}
|
onChange={repeaterFormik.handleChange}
|
||||||
onBlur={repeaterFormik.handleBlur}
|
onBlur={repeaterFormik.handleBlur}
|
||||||
endAdornment={
|
bottomLabel='Gram/Ekor (g)'
|
||||||
<div className='w-full h-full flex items-center justify-center'>
|
endAdornment
|
||||||
gr/ekor
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
errorMessage={
|
errorMessage={
|
||||||
repeaterFormik.errors
|
repeaterFormik.errors
|
||||||
.production_standard_uniformity_details
|
.production_standard_uniformity_details
|
||||||
@@ -1162,7 +1203,7 @@ const ProductionStandardForm = ({
|
|||||||
type='button'
|
type='button'
|
||||||
color='error'
|
color='error'
|
||||||
variant='outline'
|
variant='outline'
|
||||||
className='min-w-24'
|
className='min-w-xs'
|
||||||
onClick={handleCancelEdit}
|
onClick={handleCancelEdit}
|
||||||
>
|
>
|
||||||
<Icon icon='mdi:close' /> Batal
|
<Icon icon='mdi:close' /> Batal
|
||||||
@@ -1178,7 +1219,7 @@ const ProductionStandardForm = ({
|
|||||||
<Button
|
<Button
|
||||||
type='submit'
|
type='submit'
|
||||||
color={editMode ? 'warning' : 'success'}
|
color={editMode ? 'warning' : 'success'}
|
||||||
className='min-w-24'
|
className='min-w-xs'
|
||||||
disabled={
|
disabled={
|
||||||
isAddingRow ||
|
isAddingRow ||
|
||||||
formik.values.project_category === ''
|
formik.values.project_category === ''
|
||||||
@@ -1195,7 +1236,7 @@ const ProductionStandardForm = ({
|
|||||||
variant='outline'
|
variant='outline'
|
||||||
color='primary'
|
color='primary'
|
||||||
onClick={toggleTableHeight}
|
onClick={toggleTableHeight}
|
||||||
className='absolute bottom-6 right-6'
|
className='absolute bottom-2 right-2'
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon={
|
icon={
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ export const useFormikErrorList = <T>(
|
|||||||
|
|
||||||
// Validate form
|
// Validate form
|
||||||
const isValid = await handleValidateForm();
|
const isValid = await handleValidateForm();
|
||||||
|
if (isValid) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
// Call onAfterValidation callback if validation passed
|
// Call onAfterValidation callback if validation passed
|
||||||
if (options?.onAfterValidation) {
|
if (options?.onAfterValidation) {
|
||||||
|
|||||||
Reference in New Issue
Block a user