mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE-170): remove total_weight from body_weights and update validation logic in RecordingForm
This commit is contained in:
@@ -17,7 +17,6 @@ type RecordingGrowingFormSchemaType = {
|
|||||||
weight: number | string;
|
weight: number | string;
|
||||||
avg_weight: number | string;
|
avg_weight: number | string;
|
||||||
qty: number | string;
|
qty: number | string;
|
||||||
total_weight: number | string;
|
|
||||||
}[];
|
}[];
|
||||||
stocks: {
|
stocks: {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
@@ -48,7 +47,6 @@ export type BodyWeightSchema = {
|
|||||||
weight: number | string;
|
weight: number | string;
|
||||||
avg_weight: number | string;
|
avg_weight: number | string;
|
||||||
qty: number | string;
|
qty: number | string;
|
||||||
total_weight: number | string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StockSchema = {
|
export type StockSchema = {
|
||||||
@@ -73,16 +71,11 @@ const BodyWeightObjectSchema: Yup.ObjectSchema<BodyWeightSchema> = Yup.object({
|
|||||||
.typeError('Berat ayam total harus berupa angka!'),
|
.typeError('Berat ayam total harus berupa angka!'),
|
||||||
avg_weight: Yup.number()
|
avg_weight: Yup.number()
|
||||||
.required('Berat ayam rata-rata wajib diisi!')
|
.required('Berat ayam rata-rata wajib diisi!')
|
||||||
.min(1, 'Berat ayam rata-rata minimal 1 gram!')
|
|
||||||
.typeError('Berat ayam rata-rata harus berupa angka!'),
|
.typeError('Berat ayam rata-rata harus berupa angka!'),
|
||||||
qty: Yup.number()
|
qty: Yup.number()
|
||||||
.required('Jumlah ayam wajib diisi!')
|
.required('Jumlah ayam wajib diisi!')
|
||||||
.min(1, 'Jumlah ayam minimal 1 ekor!')
|
.min(1, 'Jumlah ayam minimal 1 ekor!')
|
||||||
.typeError('Jumlah ayam harus berupa angka!'),
|
.typeError('Jumlah ayam harus berupa angka!'),
|
||||||
total_weight: Yup.number()
|
|
||||||
.required('Berat ayam total wajib diisi!')
|
|
||||||
.min(0, 'Berat ayam total tidak boleh negatif!')
|
|
||||||
.typeError('Berat ayam total harus berupa angka!'),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const StockObjectSchema: Yup.ObjectSchema<StockSchema> = Yup.object({
|
const StockObjectSchema: Yup.ObjectSchema<StockSchema> = Yup.object({
|
||||||
@@ -259,14 +252,12 @@ export const getRecordingGrowingFormInitialValues = (
|
|||||||
weight: bw.avg_weight * bw.qty,
|
weight: bw.avg_weight * bw.qty,
|
||||||
avg_weight: bw.avg_weight,
|
avg_weight: bw.avg_weight,
|
||||||
qty: bw.qty,
|
qty: bw.qty,
|
||||||
total_weight: bw.total_weight,
|
|
||||||
})
|
})
|
||||||
) ?? [
|
) ?? [
|
||||||
{
|
{
|
||||||
weight: '',
|
weight: '',
|
||||||
avg_weight: '',
|
avg_weight: '',
|
||||||
qty: '',
|
qty: '',
|
||||||
total_weight: 0,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
stocks: initialValues?.stocks?.map((stock) => ({
|
stocks: initialValues?.stocks?.map((stock) => ({
|
||||||
|
|||||||
@@ -157,16 +157,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
return {
|
return {
|
||||||
project_flock_kandang_id: values.project_flock_kandang_id,
|
project_flock_kandang_id: values.project_flock_kandang_id,
|
||||||
body_weights: (values.body_weights ?? []).map((bw) => {
|
body_weights: (values.body_weights ?? []).map((bw) => {
|
||||||
const qty = Number(bw.qty) || 0;
|
|
||||||
const weight = Number(bw.weight) || 0;
|
|
||||||
const totalWeight = qty * weight;
|
|
||||||
return {
|
return {
|
||||||
avg_weight:
|
avg_weight:
|
||||||
typeof bw.avg_weight === 'number'
|
typeof bw.avg_weight === 'number'
|
||||||
? bw.avg_weight
|
? bw.avg_weight
|
||||||
: parseFloat(String(bw.avg_weight)) || 0,
|
: parseFloat(String(bw.avg_weight)) || 0,
|
||||||
qty: qty,
|
qty: Number(bw.qty) || 0,
|
||||||
total_weight: parseFloat(String(totalWeight)) || 0,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
stocks: (values.stocks ?? []).map((stock) => ({
|
stocks: (values.stocks ?? []).map((stock) => ({
|
||||||
@@ -1188,9 +1184,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const newBodyWeights = [
|
const newBodyWeights = [
|
||||||
...(formik.values.body_weights || []),
|
...(formik.values.body_weights || []),
|
||||||
{
|
{
|
||||||
weight: 0,
|
weight: '',
|
||||||
avg_weight: 0,
|
avg_weight: '',
|
||||||
qty: 1,
|
qty: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
formik.setFieldValue('body_weights', newBodyWeights);
|
formik.setFieldValue('body_weights', newBodyWeights);
|
||||||
@@ -1214,7 +1210,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const avgWeight = parseFloat((value / qty).toFixed(2));
|
const avgWeight = parseFloat((value / qty).toFixed(2));
|
||||||
formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight);
|
formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight);
|
||||||
} else {
|
} else {
|
||||||
formik.setFieldValue(`body_weights.${idx}.avg_weight`, 0);
|
formik.setFieldValue(`body_weights.${idx}.avg_weight`, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
formik.setFieldValue(`body_weights.${idx}.total_weight`, totalWeight);
|
formik.setFieldValue(`body_weights.${idx}.total_weight`, totalWeight);
|
||||||
@@ -1262,7 +1258,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const avgWeight = parseFloat((weight / value).toFixed(2));
|
const avgWeight = parseFloat((weight / value).toFixed(2));
|
||||||
formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight);
|
formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight);
|
||||||
} else {
|
} else {
|
||||||
formik.setFieldValue(`body_weights.${idx}.avg_weight`, 0);
|
formik.setFieldValue(`body_weights.${idx}.avg_weight`, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
formik.setFieldValue(`body_weights.${idx}.total_weight`, totalWeight);
|
formik.setFieldValue(`body_weights.${idx}.total_weight`, totalWeight);
|
||||||
|
|||||||
-1
@@ -92,7 +92,6 @@ export type CreateGrowingRecordingPayload = {
|
|||||||
body_weights: {
|
body_weights: {
|
||||||
avg_weight: number;
|
avg_weight: number;
|
||||||
qty: number;
|
qty: number;
|
||||||
total_weight: number;
|
|
||||||
}[];
|
}[];
|
||||||
stocks?: {
|
stocks?: {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user