mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
refactor(FE): Add default empty product and delivery rows
This commit is contained in:
@@ -226,20 +226,23 @@ export const getMovementFormInitialValues = (
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
||||||
products:
|
products: initialValues?.details?.map((detail) => ({
|
||||||
initialValues?.details?.map((detail) => ({
|
|
||||||
product: {
|
product: {
|
||||||
value: detail.product.id,
|
value: detail.product.id,
|
||||||
label: detail.product.name,
|
label: detail.product.name,
|
||||||
},
|
},
|
||||||
product_id: detail.product.id,
|
product_id: detail.product.id,
|
||||||
product_qty: detail.quantity,
|
product_qty: detail.quantity,
|
||||||
})) ?? [],
|
})) ?? [
|
||||||
deliveries:
|
{
|
||||||
initialValues?.deliveries?.map((d) => ({
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
deliveries: initialValues?.deliveries?.map((d) => ({
|
||||||
delivery_cost: d.shipping_cost_total ?? undefined,
|
delivery_cost: d.shipping_cost_total ?? undefined,
|
||||||
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
||||||
document_number: d.document_number ?? '',
|
|
||||||
document: d.document ?? null,
|
document: d.document ?? null,
|
||||||
document_path: d.document_path ?? null,
|
document_path: d.document_path ?? null,
|
||||||
driver_name: d.driver_name ?? '',
|
driver_name: d.driver_name ?? '',
|
||||||
@@ -261,6 +264,24 @@ export const getMovementFormInitialValues = (
|
|||||||
product_qty: item.quantity,
|
product_qty: item.quantity,
|
||||||
};
|
};
|
||||||
}) ?? [],
|
}) ?? [],
|
||||||
})) ?? [],
|
})) ?? [
|
||||||
|
{
|
||||||
|
delivery_cost: undefined,
|
||||||
|
delivery_cost_per_item: undefined,
|
||||||
|
document: null,
|
||||||
|
document_path: null,
|
||||||
|
driver_name: '',
|
||||||
|
vehicle_plate: '',
|
||||||
|
supplier: null,
|
||||||
|
supplier_id: 0,
|
||||||
|
products: [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -761,8 +761,36 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
type !== 'edit' &&
|
type !== 'edit' &&
|
||||||
type !== 'detail'
|
type !== 'detail'
|
||||||
) {
|
) {
|
||||||
formik.setFieldValue('products', []);
|
if (formik.values.products.length === 0) {
|
||||||
formik.setFieldValue('deliveries', []);
|
formik.setFieldValue('products', [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (formik.values.deliveries.length === 0) {
|
||||||
|
formik.setFieldValue('deliveries', [
|
||||||
|
{
|
||||||
|
delivery_cost: undefined,
|
||||||
|
delivery_cost_per_item: undefined,
|
||||||
|
document: null,
|
||||||
|
document_path: null,
|
||||||
|
driver_name: '',
|
||||||
|
vehicle_plate: '',
|
||||||
|
supplier: null,
|
||||||
|
supplier_id: 0,
|
||||||
|
products: [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [formik.values.source_warehouse_id]);
|
}, [formik.values.source_warehouse_id]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user