mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Fix delivery dependency tracking and init
This commit is contained in:
@@ -56,6 +56,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
const [formErrorList, setFormErrorList] = useState<string[]>([]);
|
||||
const [productQtyErrorShown, setProductQtyErrorShown] = useState(false);
|
||||
const [deliveryQtyErrorShown, setDeliveryQtyErrorShown] = useState(false);
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
|
||||
// ===== FORM HANDLERS =====
|
||||
const createMovementHandler = useCallback(
|
||||
@@ -557,7 +558,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
],
|
||||
},
|
||||
]);
|
||||
}, []);
|
||||
}, [formik.values.deliveries]);
|
||||
|
||||
const removeDelivery = useCallback(
|
||||
(i: number) => {
|
||||
@@ -1004,20 +1005,29 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
});
|
||||
}, [
|
||||
formik.values.deliveries
|
||||
?.map((d) =>
|
||||
d.products.reduce(
|
||||
?.map((d, idx) => ({
|
||||
idx,
|
||||
productQty: d.products.reduce(
|
||||
(sum, p) => sum + (parseInt(p.product_qty.toString()) || 0),
|
||||
0
|
||||
)
|
||||
),
|
||||
deliveryCost: parseInt((d.delivery_cost || '').toString()) || 0,
|
||||
deliveryCostPerItem:
|
||||
parseInt((d.delivery_cost_per_item || '').toString()) || 0,
|
||||
}))
|
||||
.map(
|
||||
(item) =>
|
||||
`${item.idx}:${item.productQty}:${item.deliveryCost}:${item.deliveryCostPerItem}`
|
||||
)
|
||||
.join(','),
|
||||
.join('|'),
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
formik.values.source_warehouse_id &&
|
||||
type !== 'edit' &&
|
||||
type !== 'detail'
|
||||
type !== 'detail' &&
|
||||
!isInitialized
|
||||
) {
|
||||
if (formik.values.products.length === 0) {
|
||||
formik.setFieldValue('products', [
|
||||
@@ -1049,8 +1059,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
},
|
||||
]);
|
||||
}
|
||||
setIsInitialized(true);
|
||||
}
|
||||
}, [formik.values.source_warehouse_id]);
|
||||
}, [formik.values.source_warehouse_id, isInitialized, type]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user