fix product issue
This commit is contained in:
parent
3a5dd5ca3b
commit
70da187a52
@ -410,31 +410,35 @@ const EditCompanyProfile = () => {
|
||||
|
||||
// Handle adding a product
|
||||
const handleAddProduct = (product) => {
|
||||
setSelectedProducts(prev => {
|
||||
// Check if product is already selected
|
||||
const isAlreadySelected = prev.some(p =>
|
||||
(p.value && p.value === product.value) ||
|
||||
(p.id && p.id === product.id) ||
|
||||
(p.product_id && p.product_id === product.product_id)
|
||||
);
|
||||
|
||||
if (isAlreadySelected) {
|
||||
return prev; // Don't add duplicate
|
||||
}
|
||||
|
||||
// Count current newly added products (excluding original products)
|
||||
const currentNewlyAdded = prev.filter(p => newlyAddedProductIds.has(p.value || p.id || p.product_id));
|
||||
|
||||
// Allow up to 4 newly added products
|
||||
if (currentNewlyAdded.length >= 4) {
|
||||
alert('Maximum of 4 replacement products can be added.');
|
||||
return prev;
|
||||
}
|
||||
|
||||
return [...prev, { ...product, isExisting: false }];
|
||||
});
|
||||
// Check if product is already selected
|
||||
const isAlreadySelected = selectedProducts.some(p =>
|
||||
(p.value && p.value === product.value) ||
|
||||
(p.id && p.id === product.id) ||
|
||||
(p.product_id && p.product_id === product.product_id)
|
||||
);
|
||||
|
||||
// Remove from available products
|
||||
if (isAlreadySelected) {
|
||||
// Check if the product is in selectedProducts but unchecked
|
||||
const productId = product.value || product.id || product.product_id;
|
||||
if (!checkedProducts.has(productId)) {
|
||||
alert('This product is already in your selected products but is unchecked. Please check the box next to the product in the "Selected Products" panel to include it.');
|
||||
}
|
||||
return; // Don't add duplicate, don't modify available products
|
||||
}
|
||||
|
||||
// Count current newly added products (excluding original products)
|
||||
const currentNewlyAdded = selectedProducts.filter(p => newlyAddedProductIds.has(p.value || p.id || p.product_id));
|
||||
|
||||
// Allow up to 4 newly added products
|
||||
if (currentNewlyAdded.length >= 4) {
|
||||
alert('Maximum of 4 replacement products can be added.');
|
||||
return; // Don't add product, don't modify available products
|
||||
}
|
||||
|
||||
// Only proceed with adding the product if we pass all checks
|
||||
setSelectedProducts(prev => [...prev, { ...product, isExisting: false }]);
|
||||
|
||||
// Remove from available products (only if product was actually added)
|
||||
setAvailableProducts(prev =>
|
||||
prev.filter(p =>
|
||||
!(p.value && p.value === product.value) &&
|
||||
|
||||
Loading…
Reference in New Issue
Block a user