Skip to main content
The product management system provides full CRUD operations through the AdminContext and modal-based forms. All operations interact with a MockAPI backend.

API Configuration

The admin panel connects to MockAPI for product data:
Reference: /workspace/source/src/context/AdminContext.jsx:12

Product Data Structure

Products contain the following fields:
string
required
Auto-generated product identifier
string
required
Product name
number
required
Product price (must be greater than 0)
string
required
Product description (minimum 10 characters)
number
Available stock quantity
string
URL to product image
string
Product category

Adding Products

Opening the Add Form

Click the “Abrir panel agregar producto” button to open the FormularioProducto modal:
Reference: /workspace/source/src/layout/Admin.jsx:61

Form Validation

The add form includes validation rules:
Reference: /workspace/source/src/components/FormularioProducto.jsx:17-25

API Call: POST Request

When the form is submitted, the agregarProducto function sends a POST request:
Reference: /workspace/source/src/context/AdminContext.jsx:30-54
After adding a product, cargarProductos() is called to refresh the product list.

Editing Products

Opening the Edit Form

Click the “Editar” button on any product card:
Reference: /workspace/source/src/layout/Admin.jsx:50-53 This opens the FormularioEdicion modal with the selected product data pre-filled.

Edit Form Fields

The edit form (FormularioEdicion) includes all product fields:
  • ID (read-only)
  • Nombre (text input)
  • Precio (number input, min: 0)
  • Stock (number input)
  • Imagen (text input for URL)
  • Categoría (text input)
  • Descripción (textarea)
Reference: /workspace/source/src/components/FormularioEdicion.jsx:35-124

API Call: PUT Request

The actualizarProducto function sends a PUT request:
Reference: /workspace/source/src/context/AdminContext.jsx:101-126

Deleting Products

Triggering Delete

Click the “Eliminar” button on any product card:
Reference: /workspace/source/src/layout/Admin.jsx:54

Confirmation Dialog

Before deleting, a SweetAlert2 confirmation dialog appears:
Reference: /workspace/source/src/context/AdminContext.jsx:70-76

API Call: DELETE Request

If confirmed, a DELETE request is sent:
Reference: /workspace/source/src/context/AdminContext.jsx:78-99

Loading Products

Products are loaded automatically when the AdminContext mounts:
Reference: /workspace/source/src/context/AdminContext.jsx:14-28
A 2-second delay is added to simulate loading time and show the loading state.

Reload Function

After any CRUD operation, products are reloaded:
Reference: /workspace/source/src/context/AdminContext.jsx:56-64

User Feedback

All operations use SweetAlert2 for user feedback:

Success

Shown after successful add, edit, or delete

Error

Shown when operations fail

Warning

Shown before delete confirmation