fix product issue

This commit is contained in:
Malini 2026-02-20 10:25:50 +05:30
parent bc7f850337
commit 3a5dd5ca3b

View File

@ -329,8 +329,6 @@ const EditCompanyProfile = () => {
(p.product_id && p.product_id === productValue)
);
if (newChecked.has(productValue)) {
// Unchecking: move product from selected to available
newChecked.delete(productValue);
@ -345,17 +343,15 @@ const EditCompanyProfile = () => {
);
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;
});
}
} else {
// Re-checking: remove newly added products and restore original
if (newChecked.size < selectedProducts.length) {
newChecked.add(productValue);
}
// Re-checking: add the product back to checked
newChecked.add(productValue);
// Remove from available products
setAvailableProducts(prev =>
@ -391,8 +387,8 @@ const EditCompanyProfile = () => {
const productsToAdd = newlyAddedProducts.filter(np =>
!prev.some(p =>
(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.product_id && (p.product_id === np.product_id || np.product_id === np.id || np.product_id === np.value))
(p.id && (p.id === np.id || p.id === np.value || p.id === np.product_id)) ||
(p.product_id && (p.product_id === np.product_id || p.product_id === np.id || p.product_id === np.value))
)
);
return [...prev, ...productsToAdd];
@ -401,7 +397,7 @@ const EditCompanyProfile = () => {
// Clear newly added product IDs
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);
}
}