diff --git a/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx b/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx index 3ac8278..8d4770e 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx @@ -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 = () => { )}