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