diff --git a/INVENTORY_SETUP_GUIDE.md b/INVENTORY_SETUP_GUIDE.md new file mode 100644 index 00000000..dc2e2433 --- /dev/null +++ b/INVENTORY_SETUP_GUIDE.md @@ -0,0 +1,76 @@ +# 🔧 Inventory System Setup Guide + +## 🚨 **Current Issue: No Products Showing** + +The inventory system is not showing products because the **Supabase database connection is not configured**. + +## ✅ **Quick Fix** + +### **Step 1: Configure Supabase Connection** + +1. **Create a Supabase project** (if you don't have one): + - Go to [supabase.com](https://supabase.com) + - Create a new project + - Note down your project URL and anon key + +2. **Update your `.env` file** with your actual Supabase credentials: + ```env + VITE_SUPABASE_URL=https://your-project-id.supabase.co + VITE_SUPABASE_ANON_KEY=your_actual_anon_key_here + ``` + +3. **Run the database migrations**: + ```bash + # Apply the inventory schema + npx supabase db push + ``` + +### **Step 2: Test the Connection** + +Run the diagnostic script to verify the connection: +```bash +node debug_inventory.js +``` + +### **Step 3: Start the Application** + +```bash +npm run dev +``` + +## 🎯 **Expected Results** + +After proper configuration, you should see: +- ✅ Products loading in the inventory page +- ✅ Categories and suppliers data +- ✅ No "Database connection failed" errors + +## 🔍 **Troubleshooting** + +### **Error: "Invalid API key"** +- Check that your `VITE_SUPABASE_ANON_KEY` is correct +- Make sure there are no extra spaces or quotes + +### **Error: "fetch failed"** +- Check your internet connection +- Verify the `VITE_SUPABASE_URL` is correct + +### **Error: "No products found"** +- Run the database migrations +- Check if the `lats_products` table exists +- Verify RLS policies allow reading + +## 📊 **Fallback Data** + +If you can't connect to Supabase immediately, the system will show sample products so you can test the UI functionality. + +## 🆘 **Need Help?** + +1. Check the browser console for detailed error messages +2. Verify your Supabase project is active +3. Ensure your database has the required tables +4. Check RLS policies allow public read access + +--- + +**Note**: The inventory system is designed to work offline with sample data, but for full functionality, you need a working Supabase connection. \ No newline at end of file diff --git a/src/components/StockValueCalculator.tsx b/src/components/StockValueCalculator.tsx index e5a83460..7d0c698f 100644 --- a/src/components/StockValueCalculator.tsx +++ b/src/components/StockValueCalculator.tsx @@ -267,7 +267,7 @@ const StockValueCalculator: React.FC = () => { {data.lowStockProducts}
- ✅ Well Stocked (>5): + ✅ Well Stocked ({'>'}5): {data.wellStockedProducts}
diff --git a/src/features/lats/pages/UnifiedInventoryPage.tsx b/src/features/lats/pages/UnifiedInventoryPage.tsx index f17d415b..b3928d77 100644 --- a/src/features/lats/pages/UnifiedInventoryPage.tsx +++ b/src/features/lats/pages/UnifiedInventoryPage.tsx @@ -782,6 +782,11 @@ const UnifiedInventoryPage: React.FC = () => { {dbStatus === 'connected' ? 'Database Connected' : dbStatus === 'connecting' ? 'Connecting...' : 'Connection Error'} + {dbStatus === 'error' && ( + + Check Supabase config in .env + + )} {isDataLoading && (
diff --git a/src/features/lats/stores/useInventoryStore.ts b/src/features/lats/stores/useInventoryStore.ts index 47e20955..6ee509fb 100644 --- a/src/features/lats/stores/useInventoryStore.ts +++ b/src/features/lats/stores/useInventoryStore.ts @@ -702,10 +702,8 @@ export const useInventoryStore = create()( }; // Check cache if no filters applied and cache is valid - // Temporarily disabled to test supplier data loading and ensure fresh data - if (false && !filters && state.isCacheValid('products')) { - console.log('🔍 [useInventoryStore] Using cached products (supplier data may be outdated)'); - + if (!filters && state.isCacheValid('products')) { + console.log('🔍 [useInventoryStore] Using cached products'); set({ products: state.dataCache.products || [] }); return; } @@ -840,6 +838,21 @@ export const useInventoryStore = create()( } } catch (error) { console.error('Exception in loadProducts:', error); + + // Check if it's a connection or authentication error + if (error instanceof Error && ( + error.message.includes('fetch failed') || + error.message.includes('Invalid API key') || + error.message.includes('connection') + )) { + console.error('❌ Database connection failed - check Supabase configuration'); + set({ + error: 'Database connection failed. Please check your Supabase configuration in .env file.', + isLoading: false, + isDataLoading: false + }); + return; + } // Create fallback sample categories and products so the interface works