diff --git a/src/components/pages/production/recording/form/RecordingForm.schema.ts b/src/components/pages/production/recording/form/RecordingForm.schema.ts index 4d72e053..99496843 100644 --- a/src/components/pages/production/recording/form/RecordingForm.schema.ts +++ b/src/components/pages/production/recording/form/RecordingForm.schema.ts @@ -32,6 +32,7 @@ type RecordingLayingFormSchemaType = RecordingGrowingFormSchemaType & { eggs: { product_warehouse_id: number; qty: number | string; + weight: number | string; }[]; }; @@ -62,6 +63,7 @@ export type DepletionSchema = { export type EggSchema = { product_warehouse_id: number; qty: number | string; + weight: number | string; }; const BodyWeightObjectSchema: Yup.ObjectSchema = Yup.object({ @@ -109,6 +111,10 @@ const EggObjectSchema: Yup.ObjectSchema = Yup.object({ .required('Jumlah telur wajib diisi!') .min(1, 'Jumlah telur tidak boleh 0!') .typeError('Jumlah telur harus berupa angka!'), + weight: Yup.number() + .required('Berat telur wajib diisi!') + .min(1, 'Berat telur minimal 1 gram!') + .typeError('Berat telur harus berupa angka!'), }); export const RecordingGrowingFormSchema: Yup.ObjectSchema = @@ -295,10 +301,12 @@ export const getRecordingLayingFormInitialValues = ( eggs: initialValues?.eggs?.map((egg: CreateEggPayload) => ({ product_warehouse_id: egg.product_warehouse_id, qty: egg.qty, + weight: egg.weight, })) ?? [ { product_warehouse_id: 0, qty: '', + weight: '', }, ], }); diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 43ffc98b..582e8e78 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -181,6 +181,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { eggs: (values.eggs ?? []).map((egg) => ({ product_warehouse_id: egg.product_warehouse_id, qty: Number(egg.qty) || 0, + weight: + typeof egg.weight === 'number' + ? egg.weight + : parseFloat(String(egg.weight)) || 0, })), }; }, @@ -1148,7 +1152,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { if (hasSameDayRecording) { toast.error( - `Recording untuk hari ${nextDayRecording.next_day} sudah ada. + `Recording untuk hari ${nextDayRecording.next_day} sudah ada. Tidak bisa membuat recording duplikat, mohon perbarui recording yang sudah ada terlebih dahulu.` ); return; @@ -1485,6 +1489,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { [formik] ); + const handleEggWeightChangeWrapper = useCallback( + (idx: number) => (e: React.ChangeEvent) => { + const value = parseFloat(e.target.value) || 0; + formik.setFieldValue(`eggs.${idx}.weight`, value); + }, + [formik] + ); + const removeEgg = (idx: number) => { const updatedEggs = ( formik.values as RecordingLayingFormValues @@ -2688,6 +2700,32 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { placeholder='Masukkan jumlah telur' /> +
+ +
{(type as 'add' | 'edit' | 'detail') !== 'detail' && ( diff --git a/src/types/api/production/recording.d.ts b/src/types/api/production/recording.d.ts index e7b28f47..46579509 100644 --- a/src/types/api/production/recording.d.ts +++ b/src/types/api/production/recording.d.ts @@ -53,6 +53,7 @@ export type RecordingEgg = { recording_id: number; product_warehouse_id: number; qty: number; + weight: number; created_by: User; product_warehouse: ProductWarehouse; gradings?: { @@ -129,6 +130,7 @@ export type CreateGradingRecordingPayload = { export type CreateEggPayload = { product_warehouse_id: number; qty: number; + weight: number; }; export type CreateLayingRecordingPayload = CreateGrowingRecordingPayload & {