2.1 KiB
2.1 KiB
Inventory Active/Inactive Toggle Feature
Changes Implemented
1. Frontend Changes (AdminDashboard.js)
Added Toggle Function:
- Created
handleToggleActive()function to toggle product active/inactive status - Sends PUT request to
/api/admin/products/{product_id}withis_activefield - Shows toast notification on success/failure
- Refreshes inventory after toggle
Updated Inventory Table:
- Added Price column showing product price formatted as $X.XX
- Changed "Status" column to "Active" with toggle button
- Stock column highlights in red when low stock
- Active/Inactive button shows current state and toggles on click
Table Structure:
| Product | Category | Price | Stock | Threshold | Active | Actions |
|---|---|---|---|---|---|---|
| Name | Type | $XX.XX | Count | Limit | Toggle | Adjust |
2. Backend Support (Already Present)
ProductUpdate Schema:
- Already includes
is_active: Optional[bool]field - PUT endpoint
/api/admin/products/{product_id}supports updating active status
Products Endpoint Filtering:
- Public
/api/productsendpoint filters byis_active == True - Only active products appear on frontend Products page
- Inactive products hidden from customers but visible in admin
3. How It Works
Toggle Active Status:
- Admin clicks Active/Inactive button in Inventory tab
- Frontend sends PUT request with
is_active: !current_status - Backend updates product in database
- Frontend refreshes inventory list
- Toast notification confirms change
Product Visibility:
- Active products: Appear on public Products page
- Inactive products: Hidden from customers, visible in admin only
- Useful for: Seasonal items, out-of-stock, discontinued products
4. Testing
To test the feature:
- Login as admin
- Go to Admin Dashboard → Inventory tab
- See Price column and Active toggle buttons
- Click Active/Inactive button to toggle
- Check Products page - inactive products won't appear
- Toggle back to Active - product reappears on Products page