Files
bakery-ia/REDESIGN_SUMMARY.md
Claude 3a1a19d836 Complete AI inventory step redesign & add recipes next button
 RECIPES STEP FIX:
- Add onComplete prop handling to RecipesSetupStep.tsx
- Add "Next" button when recipes.length >= 1
- Show success message with recipe count
- Button hidden when in adding mode

🎯 AI INVENTORY STEP - COMPLETE REDESIGN:
Following suppliers/recipes pattern with list-based management and deferred creation.

**NEW DATA MODEL**:
- InventoryItemForm interface with isSuggested tracking
- Items stored in list (NOT created in database yet)
- Support both AI suggestions and manual entries

**NEW UI PATTERN**:
- List view with expandable cards showing AI confidence badges
- Edit/Delete buttons per item (like suppliers)
- "Add Ingredient Manually" button with full form
- Next button creates ALL items at once (deferred creation)

**KEY CHANGES**:
1. Items added to list first (not created immediately)
2. Can edit/delete both AI and manual items before creation
3. Manual ingredient addition form with full validation
4. All items created when clicking "Next" button
5. Progress indicator during creation
6. Sales data import happens after inventory creation

**UI IMPROVEMENTS**:
- "Why This Matters" info box explaining workflow
- Ingredient cards show: name, category, stock, cost, shelf life, sales data
- AI confidence badges (e.g., "IA 95%")
- Visual success indicator when minimum met
- Gradient form section matching recipe template pattern

**FILES**:
- UploadSalesDataStep.tsx: Completely rewritten (963 lines)
- RecipesSetupStep.tsx: Added Next button (2 lines)
- REDESIGN_SUMMARY.md: Complete documentation of changes

Build:  Success (21.46s)
Pattern: Now matches suppliers/recipes workflow exactly
Creation: Deferred until "Next" click (user can review/edit first)
2025-11-06 15:09:23 +00:00

189 lines
5.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AI Inventory Step Redesign - Key Differences
## Overview
Completely redesigned UploadSalesDataStep to follow the suppliers/recipes pattern with list-based management and deferred creation.
## Major Changes
### 1. **Data Model**
**BEFORE**:
```typescript
interface InventoryItem {
suggestion_id: string;
selected: boolean; // Checkbox selection
stock_quantity: number;
cost_per_unit: number;
}
```
**AFTER**:
```typescript
interface InventoryItemForm {
id: string; // UI tracking
name: string;
// ... all inventory fields
isSuggested: boolean; // Track if from AI or manual
// NO "selected" field - all items in list will be created
}
```
### 2. **Creation Timing**
**BEFORE**:
- Checkbox selection UI
- "Create Inventory" button → Creates immediately → Proceeds to next step
**AFTER**:
- List-based UI (like suppliers/recipes)
- Items added to list (NOT created yet)
- "Next" button → Creates ALL items → Proceeds to next step
### 3. **UI Pattern**
**BEFORE** (Old Pattern):
```
┌─────────────────────────────────────┐
│ ☑️ Product 1 [Edit fields inline] │
│ ☐ Product 2 [Edit fields inline] │
│ ☑️ Product 3 [Edit fields inline] │
│ │
│ [Create 2 Selected Items] │
└─────────────────────────────────────┘
```
**AFTER** (New Pattern - Like Suppliers/Recipes):
```
┌─────────────────────────────────────┐
│ Product 1 (AI 95%) [Edit][Delete]│
│ Stock: 50kg Cost: €5.00 │
│ │
│ Product 2 (Manual) [Edit][Delete]│
│ Stock: 30kg Cost: €3.00 │
│ │
│ [ Add Ingredient Manually] │
│ │
│ ────────────────────────────────── │
│ 3 ingredients - Ready! [Next →] │
└─────────────────────────────────────┘
```
### 4. **Manual Addition**
**BEFORE**: No way to add manual ingredients
**AFTER**:
- "Add Ingredient Manually" button
- Full form with all fields
- Adds to the same list as AI suggestions
- Can edit/delete both AI and manual items
### 5. **Edit/Delete**
**BEFORE**:
- Inline editing only
- No delete (just deselect)
**AFTER**:
- Click "Edit" → Opens form with all fields
- Click "Delete" → Removes from list
- Works for both AI suggestions and manual entries
### 6. **Code Structure**
**BEFORE** (Old):
```typescript
// State
const [inventoryItems, setInventoryItems] = useState<InventoryItem[]>([]);
// Selection toggle
const handleToggleSelection = (id: string) => {
setInventoryItems(items =>
items.map(item =>
item.suggestion_id === id ? { ...item, selected: !item.selected } : item
)
);
};
// Create button - immediate creation
const handleCreateInventory = async () => {
const selectedItems = inventoryItems.filter(item => item.selected);
// Create immediately...
await Promise.all(creationPromises);
onComplete(); // Then proceed
};
```
**AFTER** (New):
```typescript
// State
const [inventoryItems, setInventoryItems] = useState<InventoryItemForm[]>([]);
const [isAdding, setIsAdding] = useState(false);
const [editingId, setEditingId] = useState<string | null>(null);
const [formData, setFormData] = useState<InventoryItemForm>({ ... });
// Add/Edit item in list (NOT in database)
const handleSubmitForm = (e: React.FormEvent) => {
if (editingId) {
// Update in list
setInventoryItems(items => items.map(item =>
item.id === editingId ? { ...formData, id: editingId } : item
));
} else {
// Add to list
setInventoryItems(items => [...items, newItem]);
}
resetForm();
};
// Delete from list
const handleDelete = (itemId: string) => {
setInventoryItems(items => items.filter(item => item.id !== itemId));
};
// Next button - create ALL at once
const handleNext = async () => {
// Create ALL items in the list
const creationPromises = inventoryItems.map(item => createIngredient.mutateAsync(...));
await Promise.allSettled(creationPromises);
onComplete(); // Then proceed
};
```
### 7. **Component Sections**
**BEFORE**: 2 main sections
1. File upload view
2. Checkbox selection + edit view
**AFTER**: 2 main sections
1. File upload view (same)
2. **List management view**:
- "Why This Matters" info box
- Ingredient list (cards with edit/delete)
- Add/Edit form (appears on click)
- Navigation with "Next" button
## Key Benefits
**Consistent UI**: Matches suppliers/recipes pattern exactly
**Flexibility**: Users can review, edit, delete, and add items before creating
**Deferred Creation**: All items created at once when clicking "Next"
**Manual Addition**: Users can add ingredients beyond AI suggestions
**Better UX**: Clear "Edit" and "Delete" actions per item
**Unified Pattern**: Same workflow for AI and manual items
## Files Changed
- `/home/user/bakery_ia/frontend/src/components/domain/onboarding/steps/UploadSalesDataStep.tsx` - **Completely rewritten** (963 lines)
- `/home/user/bakery_ia/frontend/src/components/domain/setup-wizard/steps/RecipesSetupStep.tsx` - Added Next button (2 lines)
## Testing Checklist
- [ ] Upload sales data file → AI suggestions load correctly
- [ ] Edit AI suggestion → Changes saved to list
- [ ] Delete AI suggestion → Removed from list
- [ ] Add manual ingredient → Added to list
- [ ] Edit manual ingredient → Changes saved
- [ ] Delete manual ingredient → Removed from list
- [ ] Click "Next" with 0 items → Error shown
- [ ] Click "Next" with items → All created and proceeds to next step
- [ ] Form validation works (required fields, min values)
- [ ] UI matches suppliers/recipes styling