Files
PromptTech/docs/reports/test_inventory_toggle.md

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} with is_active field
  • 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/products endpoint filters by is_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:

  1. Admin clicks Active/Inactive button in Inventory tab
  2. Frontend sends PUT request with is_active: !current_status
  3. Backend updates product in database
  4. Frontend refreshes inventory list
  5. 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:

  1. Login as admin
  2. Go to Admin Dashboard → Inventory tab
  3. See Price column and Active toggle buttons
  4. Click Active/Inactive button to toggle
  5. Check Products page - inactive products won't appear
  6. Toggle back to Active - product reappears on Products page