diff --git a/ipi-survey-platform/src/components/overview/DetailedOverview.jsx b/ipi-survey-platform/src/components/overview/DetailedOverview.jsx
index d0cbdbb..6b37f84 100644
--- a/ipi-survey-platform/src/components/overview/DetailedOverview.jsx
+++ b/ipi-survey-platform/src/components/overview/DetailedOverview.jsx
@@ -129,7 +129,10 @@ export const DetailedOverview = ({ submission, onBack }) => {
const matchesStatus = selectedStatus === '' ||
(selectedStatus === 'pending' && !product.is_active) ||
- (selectedStatus === 'approved' && product.is_active);
+ (selectedStatus === 'approved' && product.is_active)
+ (selectedStatus === 'resubmitted' && product.status === 'Resubmitted')
+ (selectedStatus === 'submitted' && product.status === 'Submitted')
+ (selectedStatus === 'rejected' && product.status === 'Rejected');
return matchesSearch && matchesStatus;
});
@@ -362,6 +365,7 @@ export const DetailedOverview = ({ submission, onBack }) => {
+
{
try {
const establishmentId = sessionStorage.getItem('establishment_id');
- if (!establishmentId) {
- console.error('Establishment ID not found in session storage');
- return;
- }
+ if (!establishmentId) return;
- const response = await fetchEstablishmentDetail(establishmentId);
- if (response && response.data && Array.isArray(response.data.establishment_products)) {
- // Transform products data to match the expected format
- const formattedProducts = response.data.establishment_products.map(item => {
- const product = item.product || {};
- return {
- value: item.product_id, // Use product_id as the value
- label: product.product_name ?
- `${product.product_name} (${product.hs_code || 'N/A'})` :
- 'Unknown Product',
- originalData: product, // Store the full product data
- hsCode: product.hs_code // Store HS code separately for display
- };
- });
-
- // Update the product options state
- setProductOptions(formattedProducts);
-
- // If you need to update the form with initial products, uncomment and modify:
- // if (formattedProducts.length > 0) {
- // const initialProducts = formattedProducts.map((product, index) => ({
- // id: index + 1,
- // product: product.value,
- // unit: '',
- // // ... other default values
- // }));
- // onProductsChange(initialProducts);
- // }
- }
+ const fetchProducts = async () => {
+ setIsLoadingProducts(true);
+ setProductsError('');
+ try {
+ // Get products from getEstablishmentProducts
+ const apiResponse = await getEstablishmentProducts(establishmentId);
+ console.log('Products from API:', apiResponse); // Debug log
+
+ // Ensure we're working with an array and handle the response structure
+ const productsList = Array.isArray(apiResponse) ? apiResponse : (apiResponse?.data || []);
+
+ const formattedProducts = productsList.map(product => {
+ // Handle nested properties with dot notation
+ const productName = product['product.product_name'] || product.product_name || '';
+ const hsCode = product['product.hs_code'] || product.hs_code || '';
+ const unitName = product['product.unit.uom'] || '';
+
+ return {
+ value: product.id.toString(),
+ label: hsCode ? `${hsCode} - ${productName}` : productName,
+ originalData: product,
+ hsCode: hsCode,
+ name: productName,
+ productId: product.product_id, // Use product_id instead of id
+ product_id: product.product_id, // Add product_id directly to the object
+ unit: unitName
+ };
+ });
+
+
+ console.log('Formatted products:', formattedProducts); // Debug log
+ setProductOptions(formattedProducts);
+ } catch (error) {
+ console.error('Error fetching products:', error);
+ setProductsError('Failed to load products. Please try again.');
+ } finally {
+ setIsLoadingProducts(false);
+ }
+ };
+
+ await fetchProducts();
} catch (err) {
- console.error('Error fetching establishment products:', err);
- setError('Failed to load establishment products');
+ console.error('Error in fetchEstablishmentProducts:', err);
+ setProductsError('Failed to load establishment products. Please try again.');
+ setIsLoadingProducts(false);
}
};
fetchEstablishmentProducts();
}, []);
+ // Moved inside the component
React.useEffect(() => {
const maxId = products.reduce((max, item) => (item && typeof item.id === 'number' ? Math.max(max, item.id) : max), 0);
if (maxId >= nextId.current) {
@@ -926,8 +937,8 @@ const handleProductSelect = async (productId, establishmentId, id) => {