mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-174): add grading and egg handling to daily recording form
This commit is contained in:
@@ -2,6 +2,8 @@ import * as Yup from 'yup';
|
||||
import {
|
||||
Recording,
|
||||
CreateGrowingRecordingPayload,
|
||||
CreateLayingRecordingPayload,
|
||||
CreateEggPayload,
|
||||
} from '@/types/api/production/recording';
|
||||
|
||||
export const RecordingGrowingFormSchema = Yup.object({
|
||||
@@ -64,7 +66,7 @@ export const RecordingGrowingFormSchema = Yup.object({
|
||||
.typeError('Produk harus berupa angka!'),
|
||||
usage_qty: Yup.number()
|
||||
.required('Jumlah penggunaan wajib diisi!')
|
||||
.min(0, 'Jumlah penggunaan tidak boleh negatif!')
|
||||
.min(1, 'Jumlah penggunaan tidak boleh 0!')
|
||||
.typeError('Jumlah penggunaan harus berupa angka!'),
|
||||
})
|
||||
)
|
||||
@@ -87,6 +89,24 @@ export const RecordingGrowingFormSchema = Yup.object({
|
||||
.required('Data depletions wajib diisi!'),
|
||||
});
|
||||
|
||||
export const RecordingLayingFormSchema = RecordingGrowingFormSchema.shape({
|
||||
eggs: Yup.array()
|
||||
.of(
|
||||
Yup.object({
|
||||
product_warehouse_id: Yup.number()
|
||||
.required('Produk telur wajib diisi!')
|
||||
.min(1, 'Produk telur wajib diisi!')
|
||||
.typeError('Produk telur harus berupa angka!'),
|
||||
qty: Yup.number()
|
||||
.required('Jumlah telur wajib diisi!')
|
||||
.min(1, 'Jumlah telur tidak boleh 0!')
|
||||
.typeError('Jumlah telur harus berupa angka!'),
|
||||
})
|
||||
)
|
||||
.min(1, 'Minimal harus ada 1 data telur!')
|
||||
.required('Data telur wajib diisi!'),
|
||||
});
|
||||
|
||||
export const UpdateRecordingGrowingFormSchema =
|
||||
RecordingGrowingFormSchema.shape({
|
||||
project_flock_kandangs_id: Yup.number()
|
||||
@@ -100,14 +120,31 @@ export const UpdateRecordingGrowingFormSchema =
|
||||
.required('Project Flock Kandang wajib diisi!'),
|
||||
});
|
||||
|
||||
export const UpdateRecordingLayingFormSchema = RecordingLayingFormSchema.shape({
|
||||
project_flock_kandangs_id: Yup.number()
|
||||
.default(0)
|
||||
.typeError('Project Flock Kandang wajib diisi!')
|
||||
.test(
|
||||
'is-valid-project-flock-kandang',
|
||||
'Project Flock Kandang wajib diisi!',
|
||||
(value) => value !== undefined && value !== null && value > 0
|
||||
)
|
||||
.required('Project Flock Kandang wajib diisi!'),
|
||||
});
|
||||
|
||||
export type RecordingGrowingFormValues = Yup.InferType<
|
||||
typeof RecordingGrowingFormSchema
|
||||
>;
|
||||
|
||||
export type RecordingLayingFormValues = Yup.InferType<
|
||||
typeof RecordingLayingFormSchema
|
||||
>;
|
||||
|
||||
type RecordingFormData = Partial<Recording> & {
|
||||
body_weights?: CreateGrowingRecordingPayload['body_weights'];
|
||||
stocks?: CreateGrowingRecordingPayload['stocks'];
|
||||
depletions?: CreateGrowingRecordingPayload['depletions'];
|
||||
eggs?: CreateLayingRecordingPayload['eggs'];
|
||||
};
|
||||
|
||||
export const getRecordingGrowingFormInitialValues = (
|
||||
@@ -158,3 +195,19 @@ export const getRecordingGrowingFormInitialValues = (
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export const getRecordingLayingFormInitialValues = (
|
||||
initialValues?: RecordingFormData
|
||||
): RecordingLayingFormValues => ({
|
||||
...getRecordingGrowingFormInitialValues(initialValues),
|
||||
|
||||
eggs: initialValues?.eggs?.map((egg: CreateEggPayload) => ({
|
||||
product_warehouse_id: egg.product_warehouse_id,
|
||||
qty: egg.qty,
|
||||
})) ?? [
|
||||
{
|
||||
product_warehouse_id: 0,
|
||||
qty: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
+14
-19
@@ -85,33 +85,28 @@ export type CreateGrowingRecordingPayload = {
|
||||
}[];
|
||||
};
|
||||
|
||||
export type CreateLayingRecordingPayload = {
|
||||
project_flock_kandangs_id: number;
|
||||
body_weights: {
|
||||
avg_weight: number;
|
||||
qty: number;
|
||||
}[];
|
||||
stocks?: {
|
||||
export type CreateGradingPayload = {
|
||||
recording_id: number;
|
||||
grading: {
|
||||
product_warehouse_id: number;
|
||||
usage_qty: number;
|
||||
}[];
|
||||
depletions?: {
|
||||
product_warehouse_id: number;
|
||||
qty: number;
|
||||
}[];
|
||||
eggs: {
|
||||
product_warehouse_id: number;
|
||||
qty: number;
|
||||
grading?: {
|
||||
grade: string;
|
||||
qty: number;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
export type CreateEggPayload = {
|
||||
product_warehouse_id: number;
|
||||
qty: number;
|
||||
};
|
||||
|
||||
export type CreateLayingRecordingPayload = CreateGrowingRecordingPayload & {
|
||||
eggs?: CreateEggPayload[];
|
||||
};
|
||||
|
||||
export type CreateRecordingPayload =
|
||||
| CreateGrowingRecordingPayload
|
||||
| CreateLayingRecordingPayload;
|
||||
| CreateLayingRecordingPayload
|
||||
| CreateGradingRecordingPayload;
|
||||
|
||||
export type UpdateGrowingRecordingPayload = CreateGrowingRecordingPayload;
|
||||
export type UpdateLayingRecordingPayload = CreateLayingRecordingPayload;
|
||||
|
||||
Reference in New Issue
Block a user