archive products
This commit is contained in:
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user