From 9c69369a51c7b375987a38b9651b98156c9c8ba9 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Wed, 19 Nov 2025 18:04:15 +0700 Subject: [PATCH] feat(FE-170): remove total_weight from body_weights and update validation logic in RecordingForm --- .../recording/form/RecordingForm.schema.ts | 9 --------- .../production/recording/form/RecordingForm.tsx | 16 ++++++---------- src/types/api/production/recording.d.ts | 1 - 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/components/pages/production/recording/form/RecordingForm.schema.ts b/src/components/pages/production/recording/form/RecordingForm.schema.ts index dd13aa0b..4d72e053 100644 --- a/src/components/pages/production/recording/form/RecordingForm.schema.ts +++ b/src/components/pages/production/recording/form/RecordingForm.schema.ts @@ -17,7 +17,6 @@ type RecordingGrowingFormSchemaType = { weight: number | string; avg_weight: number | string; qty: number | string; - total_weight: number | string; }[]; stocks: { product_warehouse_id: number; @@ -48,7 +47,6 @@ export type BodyWeightSchema = { weight: number | string; avg_weight: number | string; qty: number | string; - total_weight: number | string; }; export type StockSchema = { @@ -73,16 +71,11 @@ const BodyWeightObjectSchema: Yup.ObjectSchema = Yup.object({ .typeError('Berat ayam total harus berupa angka!'), avg_weight: Yup.number() .required('Berat ayam rata-rata wajib diisi!') - .min(1, 'Berat ayam rata-rata minimal 1 gram!') .typeError('Berat ayam rata-rata harus berupa angka!'), qty: Yup.number() .required('Jumlah ayam wajib diisi!') .min(1, 'Jumlah ayam minimal 1 ekor!') .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 = Yup.object({ @@ -259,14 +252,12 @@ export const getRecordingGrowingFormInitialValues = ( weight: bw.avg_weight * bw.qty, avg_weight: bw.avg_weight, qty: bw.qty, - total_weight: bw.total_weight, }) ) ?? [ { weight: '', avg_weight: '', qty: '', - total_weight: 0, }, ], stocks: initialValues?.stocks?.map((stock) => ({ diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 03975a09..b0f77e03 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -157,16 +157,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { return { project_flock_kandang_id: values.project_flock_kandang_id, body_weights: (values.body_weights ?? []).map((bw) => { - const qty = Number(bw.qty) || 0; - const weight = Number(bw.weight) || 0; - const totalWeight = qty * weight; return { avg_weight: typeof bw.avg_weight === 'number' ? bw.avg_weight : parseFloat(String(bw.avg_weight)) || 0, - qty: qty, - total_weight: parseFloat(String(totalWeight)) || 0, + qty: Number(bw.qty) || 0, }; }), stocks: (values.stocks ?? []).map((stock) => ({ @@ -1188,9 +1184,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { const newBodyWeights = [ ...(formik.values.body_weights || []), { - weight: 0, - avg_weight: 0, - qty: 1, + weight: '', + avg_weight: '', + qty: '', }, ]; formik.setFieldValue('body_weights', newBodyWeights); @@ -1214,7 +1210,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { const avgWeight = parseFloat((value / qty).toFixed(2)); formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight); } else { - formik.setFieldValue(`body_weights.${idx}.avg_weight`, 0); + formik.setFieldValue(`body_weights.${idx}.avg_weight`, ''); } 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)); formik.setFieldValue(`body_weights.${idx}.avg_weight`, avgWeight); } else { - formik.setFieldValue(`body_weights.${idx}.avg_weight`, 0); + formik.setFieldValue(`body_weights.${idx}.avg_weight`, ''); } formik.setFieldValue(`body_weights.${idx}.total_weight`, totalWeight); diff --git a/src/types/api/production/recording.d.ts b/src/types/api/production/recording.d.ts index 4abbad75..6c5a7ee9 100644 --- a/src/types/api/production/recording.d.ts +++ b/src/types/api/production/recording.d.ts @@ -92,7 +92,6 @@ export type CreateGrowingRecordingPayload = { body_weights: { avg_weight: number; qty: number; - total_weight: number; }[]; stocks?: { product_warehouse_id: number;