mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 14:55:44 +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 [formErrorList, setFormErrorList] = useState<string[]>([]);
|
||||||
const [productQtyErrorShown, setProductQtyErrorShown] = useState(false);
|
const [productQtyErrorShown, setProductQtyErrorShown] = useState(false);
|
||||||
const [deliveryQtyErrorShown, setDeliveryQtyErrorShown] = useState(false);
|
const [deliveryQtyErrorShown, setDeliveryQtyErrorShown] = useState(false);
|
||||||
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
|
||||||
// ===== FORM HANDLERS =====
|
// ===== FORM HANDLERS =====
|
||||||
const createMovementHandler = useCallback(
|
const createMovementHandler = useCallback(
|
||||||
@@ -557,7 +558,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}, []);
|
}, [formik.values.deliveries]);
|
||||||
|
|
||||||
const removeDelivery = useCallback(
|
const removeDelivery = useCallback(
|
||||||
(i: number) => {
|
(i: number) => {
|
||||||
@@ -1004,20 +1005,29 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
formik.values.deliveries
|
formik.values.deliveries
|
||||||
?.map((d) =>
|
?.map((d, idx) => ({
|
||||||
d.products.reduce(
|
idx,
|
||||||
|
productQty: d.products.reduce(
|
||||||
(sum, p) => sum + (parseInt(p.product_qty.toString()) || 0),
|
(sum, p) => sum + (parseInt(p.product_qty.toString()) || 0),
|
||||||
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(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
formik.values.source_warehouse_id &&
|
formik.values.source_warehouse_id &&
|
||||||
type !== 'edit' &&
|
type !== 'edit' &&
|
||||||
type !== 'detail'
|
type !== 'detail' &&
|
||||||
|
!isInitialized
|
||||||
) {
|
) {
|
||||||
if (formik.values.products.length === 0) {
|
if (formik.values.products.length === 0) {
|
||||||
formik.setFieldValue('products', [
|
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(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user