bug fixed in products
This commit is contained in:
parent
51a699687b
commit
2eabb47eaa
@ -360,9 +360,14 @@ const EditCompanyProfile = () => {
|
||||
)
|
||||
);
|
||||
|
||||
// If this is an original product being re-checked, remove newly added products
|
||||
if (product && product.isExisting) {
|
||||
// Find all newly added products (not original)
|
||||
// Check if all original products are now checked
|
||||
const originalProducts = selectedProducts.filter(p => p.isExisting);
|
||||
const originalProductIds = originalProducts.map(p => p.value || p.id || p.product_id);
|
||||
const allOriginalProductsChecked = originalProductIds.every(id => newChecked.has(id));
|
||||
|
||||
// If all original products are checked, remove all newly added products
|
||||
if (allOriginalProductsChecked && newlyAddedProductIds.size > 0) {
|
||||
// Find all newly added products
|
||||
const newlyAddedProducts = selectedProducts.filter(p =>
|
||||
!p.isExisting && newlyAddedProductIds.has(p.value || p.id || p.product_id)
|
||||
);
|
||||
@ -392,8 +397,8 @@ const EditCompanyProfile = () => {
|
||||
// Clear newly added product IDs
|
||||
setNewlyAddedProductIds(new Set());
|
||||
|
||||
// Show alert to user
|
||||
alert('Original product restored. Replacement products have been removed.');
|
||||
// Refresh page to update the UI
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -425,7 +430,7 @@ const EditCompanyProfile = () => {
|
||||
return prev;
|
||||
}
|
||||
|
||||
return [...prev, product];
|
||||
return [...prev, { ...product, isExisting: false }];
|
||||
});
|
||||
|
||||
// Remove from available products
|
||||
@ -622,9 +627,9 @@ const EditCompanyProfile = () => {
|
||||
product_id: productId,
|
||||
label: productData.product_name || productData.name || 'Unnamed Product',
|
||||
hs_code: productData.hs_code || '',
|
||||
product_name: productData.product_name || productData.name || 'Unnamed Product',
|
||||
isExisting: true // Mark as existing product
|
||||
product_name: productData.product_name || productData.name || 'Unnamed Product'
|
||||
}),
|
||||
isExisting: true, // Mark as existing product
|
||||
action_done_by: ep.action_done_by // Add the action_done_by field from the API response
|
||||
};
|
||||
});
|
||||
@ -1084,8 +1089,8 @@ const EditCompanyProfile = () => {
|
||||
)}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Available Products Panel - Only show if not all selected products are checked */}
|
||||
{selectedProducts.length > 0 && checkedProducts.size < selectedProducts.length && (
|
||||
{/* Available Products Panel - Only show if there are available products and not all selected products are checked */}
|
||||
{availableProducts.length > 0 && selectedProducts.length > 0 && checkedProducts.size < selectedProducts.length && (
|
||||
<div className="bg-white rounded-lg border border-[#E5E7EB] overflow-hidden">
|
||||
<div className="bg-[#F9FAFB] px-4 py-3 border-b border-[#E5E7EB]">
|
||||
<h5 className="text-sm font-medium text-[#111827]">Available Products</h5>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user