Claude
|
bedd4868ac
|
Fix invalid unit_of_measure 'dozen' causing 422 API errors
**Issue:**
Creating ingredients failed with 422 error:
```
Input should be 'kg', 'g', 'l', 'ml', 'units', 'pcs', 'pkg', 'bags' or 'boxes'
input: "dozen"
```
**Root Cause:**
Frontend was using units not supported by backend UnitOfMeasure enum:
- "dozen" (docena)
- "cup" (taza)
- "tbsp" (cucharada)
- "tsp" (cucharadita)
- "piece" → should be "pcs"
- "package" → should be "pkg"
- "bag" → should be "bags"
- "box" → should be "boxes"
**Backend Supported Units (inventory.ts:28-38):**
kg, g, l, ml, units, pcs, pkg, bags, boxes
**Solution:**
Replaced all invalid units with backend-compatible ones across codebase.
**Files Modified:**
1. **UploadSalesDataStep.tsx:604**
- Before: ['kg', 'g', 'L', 'ml', 'units', 'dozen']
- After: ['kg', 'g', 'l', 'ml', 'units', 'pcs', 'pkg', 'bags', 'boxes']
2. **BatchAddIngredientsModal.tsx:53**
- Before: ['kg', 'g', 'L', 'ml', 'units', 'dozen']
- After: ['kg', 'g', 'l', 'ml', 'units', 'pcs', 'pkg', 'bags', 'boxes']
3. **QuickAddIngredientModal.tsx:69**
- Before: ['kg', 'g', 'L', 'ml', 'units', 'dozen']
- After: ['kg', 'g', 'l', 'ml', 'units', 'pcs', 'pkg', 'bags', 'boxes']
4. **inventory/index.ts:51-62**
- Removed: 'piece', 'package', 'bag', 'box', 'dozen', 'cup', 'tbsp', 'tsp'
- Added: 'units', 'pcs', 'pkg', 'bags', 'boxes'
- Added comment: "must match backend UnitOfMeasure enum exactly"
5. **ingredientHelpers.ts:168**
- Eggs unit changed from 'dozen' → 'units'
6. **utils/constants.ts:77-87**
- Removed volume units: cup, tbsp, tsp
- Removed count units: piece, dozen, package, bag, box
- Added: units, pcs, pkg, bags, boxes
- Now matches backend enum exactly
**Also Fixed:**
- Changed 'L' to lowercase 'l' for consistency with backend
**Impact:**
✅ All ingredient creation now uses valid backend units
✅ No more 422 validation errors
✅ Frontend/backend unit enums synchronized
**Build Status:** ✓ Successful in 22.23s
|
2025-11-07 08:36:35 +00:00 |
|
Claude
|
000e352ef9
|
Implement 5 UX enhancements for ingredient management
This commit implements the requested enhancements for the ingredient
quick-add system and batch management:
**1. Duplicate Detection**
- Real-time Levenshtein distance-based similarity checking
- Shows warning with top 3 similar ingredients (70%+ similarity)
- Prevents accidental duplicate creation
- Location: QuickAddIngredientModal.tsx
**2. Smart Category Suggestions**
- Auto-populates category based on ingredient name patterns
- Supports Spanish and English ingredient names
- Shows visual indicator when category is AI-suggested
- Pattern matching for: Baking, Dairy, Fruits, Vegetables, Meat, Seafood, Spices
- Location: ingredientHelpers.ts
**3. Quick Templates**
- 10 pre-configured common bakery ingredients
- One-click template application
- Templates include: Flour, Butter, Sugar, Eggs, Yeast, Milk, Chocolate, Vanilla, Salt, Cream
- Each template has sensible defaults (shelf life, refrigeration requirements)
- Location: QuickAddIngredientModal.tsx
**4. Batch Creation Mode**
- BatchAddIngredientsModal component for adding multiple ingredients at once
- Table-based interface for efficient data entry
- "Load from Templates" quick action
- Duplicate detection within batch
- Partial success handling (some ingredients succeed, some fail)
- Location: BatchAddIngredientsModal.tsx
- Integration: UploadSalesDataStep.tsx (2 buttons: "Add One" / "Add Multiple")
**5. Dashboard Alert for Incomplete Ingredients**
- IncompleteIngredientsAlert component on dashboard
- Queries ingredients with needs_review metadata flag
- Shows count badge and first 5 incomplete ingredients
- "Complete Information" button links to inventory page
- Only shows when incomplete ingredients exist
- Location: IncompleteIngredientsAlert.tsx
- Integration: DashboardPage.tsx
**New Files Created:**
- ingredientHelpers.ts - Utilities for duplicate detection, smart suggestions, templates
- BatchAddIngredientsModal.tsx - Batch ingredient creation component
- IncompleteIngredientsAlert.tsx - Dashboard alert component
**Files Modified:**
- QuickAddIngredientModal.tsx - Added duplicate detection, smart suggestions, templates
- UploadSalesDataStep.tsx - Integrated batch creation modal
- DashboardPage.tsx - Added incomplete ingredients alert
**Technical Highlights:**
- Levenshtein distance algorithm for fuzzy name matching
- Pattern-based category suggestions (supports 100+ ingredient patterns)
- Metadata tracking (needs_review, created_context)
- Real-time validation and error handling
- Responsive UI with animations
- Consistent with existing design system
All features built and tested successfully.
Build time: 21.29s
|
2025-11-06 15:39:30 +00:00 |
|