Improve admin ban UX, add product cloning, and enhance auth handling
Refines the admin ban page with better dialog state management and feedback during ban/unban actions. Adds a product cloning feature to the products dashboard and updates the product table to support cloning. Improves error handling in ChatDetail for authentication errors, and enhances middleware to handle auth check timeouts and network errors more gracefully. Also updates BanUserCard to validate user ID and ensure correct request formatting.
This commit is contained in:
@@ -282,6 +282,31 @@ export default function ProductsPage() {
|
||||
setAddProductOpen(true);
|
||||
};
|
||||
|
||||
// Clone product - opens modal with product data but as a new product
|
||||
const handleCloneProduct = (product: Product) => {
|
||||
// Clone the product but remove _id and image to make it a new product
|
||||
const clonedProduct: Product = {
|
||||
...product,
|
||||
_id: undefined, // Remove ID so it's treated as a new product
|
||||
name: `${product.name} (Copy)`, // Add "(Copy)" to the name
|
||||
image: null, // Clear image so user can upload a new one
|
||||
pricing: product.pricing
|
||||
? product.pricing.map((tier) => ({
|
||||
minQuantity: tier.minQuantity,
|
||||
pricePerUnit: tier.pricePerUnit,
|
||||
}))
|
||||
: [{ minQuantity: 1, pricePerUnit: 0 }],
|
||||
costPerUnit: product.costPerUnit || 0,
|
||||
// Reset stock to defaults for cloned product
|
||||
currentStock: 0,
|
||||
stockStatus: 'out_of_stock' as const,
|
||||
};
|
||||
|
||||
setProductData(clonedProduct);
|
||||
setEditing(false); // Set to false so it creates a new product
|
||||
setAddProductOpen(true);
|
||||
};
|
||||
|
||||
// Reset product data when adding a new product
|
||||
const handleAddNewProduct = () => {
|
||||
setProductData({
|
||||
@@ -435,6 +460,7 @@ export default function ProductsPage() {
|
||||
products={filteredProducts}
|
||||
loading={loading}
|
||||
onEdit={handleEditProduct}
|
||||
onClone={handleCloneProduct}
|
||||
onDelete={handleDeleteProduct}
|
||||
onToggleEnabled={handleToggleEnabled}
|
||||
onProfitAnalysis={handleProfitAnalysis}
|
||||
|
||||
Reference in New Issue
Block a user