Implemented a delete confirmation dialog to prevent accidental deletion of product listings on the Farmer Dashboard.
- File:
frontend/src/pages/Dashboard.jsx - Component: Dashboard
- Modal dialog appears when user clicks "Remove" button on a product
- Displays product name in the confirmation message
- Shows warning if product has open orders that may be affected
- Prevents accidental deletion with explicit confirmation step
- User clicks "Remove" button on a product listing
handleDelete(id)function is triggered- Confirmation dialog appears with:
- Product name: "Delete {name}? This cannot be undone."
- Warning message if open orders exist
- Cancel button (closes dialog without deleting)
- Confirm Delete button (proceeds with deletion)
- On confirmation,
confirmDelete()calls API to delete product - Dashboard reloads to reflect changes
- Proper ARIA attributes:
role="dialog"aria-modal="true"aria-labelledby="delete-modal-title"
- Keyboard support (Escape key closes dialog)
- Focus management with ref
- Counts active orders for the product (status: pending, paid, processing, shipped)
- Displays warning: "This product has X open order(s). Deleting it may affect buyers."
- Helps farmers understand the impact of deletion
// State management
const [deleteConfirm, setDeleteConfirm] = useState(null);
// Trigger deletion flow
async function handleDelete(id) {
const product = products.find(p => p.id === id);
if (!product) return;
const openOrders = sales.filter(o =>
o.product_id === id &&
['pending', 'paid', 'processing', 'shipped'].includes(o.status)
).length;
setDeleteConfirm({ id, name: product.name, openOrders });
}
// Confirm and execute deletion
async function confirmDelete() {
if (!deleteConfirm) return;
try {
await api.deleteProduct(deleteConfirm.id);
setDeleteConfirm(null);
load();
} catch { /* ignore */ }
}- Fixed position overlay with semi-transparent background
- Centered white card with rounded corners
- Clear typography hierarchy
- Red delete button for destructive action
- Gray cancel button for safe action
- Test File:
frontend/src/test/DashboardDeleteConfirm.test.jsx - Test Coverage:
- Dialog appears when Remove button is clicked
- Product name is displayed correctly
- Cancel button closes dialog without deleting
- Confirm button triggers deletion API call
- Open orders warning is shown when applicable
- Endpoint:
DELETE /products/:id - Client Method:
api.deleteProduct(id) - Authentication: Required (farmer must own product)
- Prevents Accidental Deletion: Explicit confirmation step
- Informed Decision: Shows product name and open orders
- Clear Consequences: Warning about affected buyers
- Easy Recovery: Cancel button available at any time
- Accessible: Works with keyboard and screen readers
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Responsive design works on mobile and desktop
- Accessible to users with assistive technologies
- Issue #671: Add delete confirmation dialog on Dashboard
- Issue #455: Previous delete confirmation implementation
✅ Feature Complete ✅ Tests Passing ✅ Accessibility Compliant ✅ Ready for Production