fix product issue
This commit is contained in:
parent
bc7f850337
commit
3a5dd5ca3b
@ -329,8 +329,6 @@ const EditCompanyProfile = () => {
|
|||||||
(p.product_id && p.product_id === productValue)
|
(p.product_id && p.product_id === productValue)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (newChecked.has(productValue)) {
|
if (newChecked.has(productValue)) {
|
||||||
// Unchecking: move product from selected to available
|
// Unchecking: move product from selected to available
|
||||||
newChecked.delete(productValue);
|
newChecked.delete(productValue);
|
||||||
@ -345,17 +343,15 @@ const EditCompanyProfile = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!alreadyExists) {
|
if (!alreadyExists) {
|
||||||
('ADDING TO AVAILABLE - new length will be:', prev.length + 1);
|
console.log('ADDING TO AVAILABLE - new length will be:', prev.length + 1);
|
||||||
return [...prev, product];
|
return [...prev, product];
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Re-checking: remove newly added products and restore original
|
// Re-checking: add the product back to checked
|
||||||
if (newChecked.size < selectedProducts.length) {
|
newChecked.add(productValue);
|
||||||
newChecked.add(productValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove from available products
|
// Remove from available products
|
||||||
setAvailableProducts(prev =>
|
setAvailableProducts(prev =>
|
||||||
@ -391,8 +387,8 @@ const EditCompanyProfile = () => {
|
|||||||
const productsToAdd = newlyAddedProducts.filter(np =>
|
const productsToAdd = newlyAddedProducts.filter(np =>
|
||||||
!prev.some(p =>
|
!prev.some(p =>
|
||||||
(p.value && (p.value === np.value || p.value === np.id || p.value === np.product_id)) ||
|
(p.value && (p.value === np.value || p.value === np.id || p.value === np.product_id)) ||
|
||||||
(p.id && (p.id === np.id || p.id === np.value || np.id === np.product_id)) ||
|
(p.id && (p.id === np.id || p.id === np.value || p.id === np.product_id)) ||
|
||||||
(p.product_id && (p.product_id === np.product_id || np.product_id === np.id || np.product_id === np.value))
|
(p.product_id && (p.product_id === np.product_id || p.product_id === np.id || p.product_id === np.value))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return [...prev, ...productsToAdd];
|
return [...prev, ...productsToAdd];
|
||||||
@ -401,7 +397,7 @@ const EditCompanyProfile = () => {
|
|||||||
// Clear newly added product IDs
|
// Clear newly added product IDs
|
||||||
setNewlyAddedProductIds(new Set());
|
setNewlyAddedProductIds(new Set());
|
||||||
|
|
||||||
// Refresh component to update the UI while staying on current step
|
// Refresh component to update UI while staying on current step
|
||||||
navigate(window.location.pathname);
|
navigate(window.location.pathname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user