archive products

This commit is contained in:
Jake Kasper
2025-09-03 14:39:20 -04:00
parent a0bde7db23
commit 19314b301f
4 changed files with 57 additions and 6 deletions

View File

@@ -113,7 +113,18 @@ const AdminProducts = () => {
if (selectedProduct.isShared) {
await adminAPI.deleteProduct(selectedProduct.id);
} else {
await productsAPI.deleteUserProduct(selectedProduct.id);
try {
await productsAPI.deleteUserProduct(selectedProduct.id);
} catch (e) {
const msg = e?.response?.data?.message || '';
if (msg.includes('used in applications')) {
// Fallback to archive instead of delete
await productsAPI.archiveUserProduct(selectedProduct.id);
toast('Product archived instead of deleted (in use)');
} else {
throw e;
}
}
}
toast.success('Product deleted successfully');
setShowDeleteModal(false);
@@ -121,7 +132,7 @@ const AdminProducts = () => {
fetchData();
} catch (error) {
console.error('Failed to delete product:', error);
toast.error('Failed to delete product');
toast.error(error?.response?.data?.message || 'Failed to delete product');
}
};