mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Reset deliveries when products change
This commit is contained in:
@@ -1115,6 +1115,44 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
formik.errors.destination_warehouse_id,
|
formik.errors.destination_warehouse_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (formik.values.products && formik.values.deliveries) {
|
||||||
|
const productIds = formik.values.products.map((p) => p.product_id);
|
||||||
|
|
||||||
|
const updatedDeliveries = formik.values.deliveries.map((delivery) => {
|
||||||
|
const deliveryProduct = delivery.products[0];
|
||||||
|
if (deliveryProduct && deliveryProduct.product_id !== 0) {
|
||||||
|
if (!productIds.includes(deliveryProduct.product_id)) {
|
||||||
|
return {
|
||||||
|
...delivery,
|
||||||
|
products: [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
delivery_cost: '',
|
||||||
|
delivery_cost_per_item: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delivery;
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasChanges = formik.values.deliveries.some(
|
||||||
|
(delivery, idx) =>
|
||||||
|
delivery.products[0]?.product_id !==
|
||||||
|
updatedDeliveries[idx]?.products[0]?.product_id ||
|
||||||
|
delivery.delivery_cost !== updatedDeliveries[idx]?.delivery_cost
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
formik.setFieldValue('deliveries', updatedDeliveries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [formik.values.products]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (productQtyErrorShown) {
|
if (productQtyErrorShown) {
|
||||||
toast.dismiss();
|
toast.dismiss();
|
||||||
|
|||||||
Reference in New Issue
Block a user