mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
feat(FE-326): Add egg weight field to recording forms
This commit is contained in:
@@ -32,6 +32,7 @@ type RecordingLayingFormSchemaType = RecordingGrowingFormSchemaType & {
|
|||||||
eggs: {
|
eggs: {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
qty: number | string;
|
qty: number | string;
|
||||||
|
weight: number | string;
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ export type DepletionSchema = {
|
|||||||
export type EggSchema = {
|
export type EggSchema = {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
qty: number | string;
|
qty: number | string;
|
||||||
|
weight: number | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BodyWeightObjectSchema: Yup.ObjectSchema<BodyWeightSchema> = Yup.object({
|
const BodyWeightObjectSchema: Yup.ObjectSchema<BodyWeightSchema> = Yup.object({
|
||||||
@@ -109,6 +111,10 @@ const EggObjectSchema: Yup.ObjectSchema<EggSchema> = Yup.object({
|
|||||||
.required('Jumlah telur wajib diisi!')
|
.required('Jumlah telur wajib diisi!')
|
||||||
.min(1, 'Jumlah telur tidak boleh 0!')
|
.min(1, 'Jumlah telur tidak boleh 0!')
|
||||||
.typeError('Jumlah telur harus berupa angka!'),
|
.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<RecordingGrowingFormSchemaType> =
|
export const RecordingGrowingFormSchema: Yup.ObjectSchema<RecordingGrowingFormSchemaType> =
|
||||||
@@ -295,10 +301,12 @@ export const getRecordingLayingFormInitialValues = (
|
|||||||
eggs: initialValues?.eggs?.map((egg: CreateEggPayload) => ({
|
eggs: initialValues?.eggs?.map((egg: CreateEggPayload) => ({
|
||||||
product_warehouse_id: egg.product_warehouse_id,
|
product_warehouse_id: egg.product_warehouse_id,
|
||||||
qty: egg.qty,
|
qty: egg.qty,
|
||||||
|
weight: egg.weight,
|
||||||
})) ?? [
|
})) ?? [
|
||||||
{
|
{
|
||||||
product_warehouse_id: 0,
|
product_warehouse_id: 0,
|
||||||
qty: '',
|
qty: '',
|
||||||
|
weight: '',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
eggs: (values.eggs ?? []).map((egg) => ({
|
eggs: (values.eggs ?? []).map((egg) => ({
|
||||||
product_warehouse_id: egg.product_warehouse_id,
|
product_warehouse_id: egg.product_warehouse_id,
|
||||||
qty: Number(egg.qty) || 0,
|
qty: Number(egg.qty) || 0,
|
||||||
|
weight:
|
||||||
|
typeof egg.weight === 'number'
|
||||||
|
? egg.weight
|
||||||
|
: parseFloat(String(egg.weight)) || 0,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -1485,6 +1489,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
[formik]
|
[formik]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleEggWeightChangeWrapper = useCallback(
|
||||||
|
(idx: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = parseFloat(e.target.value) || 0;
|
||||||
|
formik.setFieldValue(`eggs.${idx}.weight`, value);
|
||||||
|
},
|
||||||
|
[formik]
|
||||||
|
);
|
||||||
|
|
||||||
const removeEgg = (idx: number) => {
|
const removeEgg = (idx: number) => {
|
||||||
const updatedEggs = (
|
const updatedEggs = (
|
||||||
formik.values as RecordingLayingFormValues
|
formik.values as RecordingLayingFormValues
|
||||||
@@ -2688,6 +2700,32 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
placeholder='Masukkan jumlah telur'
|
placeholder='Masukkan jumlah telur'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className='flex flex-col gap-1'>
|
||||||
|
<NumberInput
|
||||||
|
required
|
||||||
|
name={`eggs.${idx}.weight`}
|
||||||
|
value={egg.weight ?? ''}
|
||||||
|
onChange={handleEggWeightChangeWrapper(idx)}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
decimalScale={0}
|
||||||
|
allowNegative={false}
|
||||||
|
thousandSeparator=','
|
||||||
|
decimalSeparator='.'
|
||||||
|
isError={
|
||||||
|
isRepeaterInputError('eggs', 'weight', idx)
|
||||||
|
.isError
|
||||||
|
}
|
||||||
|
errorMessage={
|
||||||
|
isRepeaterInputError('eggs', 'weight', idx)
|
||||||
|
.errorMessage
|
||||||
|
}
|
||||||
|
readOnly={type === 'detail'}
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full min-w-24',
|
||||||
|
}}
|
||||||
|
placeholder='Masukkan berat telur (gram)...'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
+2
@@ -53,6 +53,7 @@ export type RecordingEgg = {
|
|||||||
recording_id: number;
|
recording_id: number;
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
qty: number;
|
qty: number;
|
||||||
|
weight: number;
|
||||||
created_by: User;
|
created_by: User;
|
||||||
product_warehouse: ProductWarehouse;
|
product_warehouse: ProductWarehouse;
|
||||||
gradings?: {
|
gradings?: {
|
||||||
@@ -129,6 +130,7 @@ export type CreateGradingRecordingPayload = {
|
|||||||
export type CreateEggPayload = {
|
export type CreateEggPayload = {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id: number;
|
||||||
qty: number;
|
qty: number;
|
||||||
|
weight: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CreateLayingRecordingPayload = CreateGrowingRecordingPayload & {
|
export type CreateLayingRecordingPayload = CreateGrowingRecordingPayload & {
|
||||||
|
|||||||
Reference in New Issue
Block a user