diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx new file mode 100644 index 0000000..3de932d --- /dev/null +++ b/src/app/admin/page.tsx @@ -0,0 +1,339 @@ +"use client"; + +import { useState } from "react"; +import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider"; +import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay'; +import { Plus, Edit2, Trash2, X, Check } from 'lucide-react'; + +interface Product { + id: string; + name: string; + price: string; + imageSrc: string; + imageAlt?: string; + size?: string; + color?: string; + stock?: number; +} + +interface FormData { + name: string; + price: string; + imageSrc: string; + imageAlt: string; + size: string; + color: string; + stock: string; +} + +export default function AdminPage() { + const [products, setProducts] = useState([ + { + id: "1", name: "Elegance Dress", price: "$89.99", imageSrc: "http://img.b2bpic.net/free-photo/fashion-portrait-young-elegant-woman_1328-2692.jpg", imageAlt: "Stylish women's dress", size: "M", color: "Black", stock: 15 + }, + { + id: "2", name: "Classic Oxford Shirt", price: "$64.99", imageSrc: "http://img.b2bpic.net/free-photo/portrait-young-confident-man-suit_171337-19984.jpg", imageAlt: "Men's button-up shirt", size: "L", color: "White", stock: 22 + }, + { + id: "3", name: "Premium Denim Jeans", price: "$79.99", imageSrc: "http://img.b2bpic.net/free-photo/woman-model-demonstrating-winter-cloths_1303-16949.jpg", imageAlt: "Classic denim jeans", size: "32", color: "Blue", stock: 18 + } + ]); + + const [isFormOpen, setIsFormOpen] = useState(false); + const [editingId, setEditingId] = useState(null); + const [formData, setFormData] = useState({ + name: "", price: "", imageSrc: "", imageAlt: "", size: "", color: "", stock: "" + }); + + const handleOpenForm = (product?: Product) => { + if (product) { + setEditingId(product.id); + setFormData({ + name: product.name, + price: product.price, + imageSrc: product.imageSrc, + imageAlt: product.imageAlt || "", size: product.size || "", color: product.color || "", stock: product.stock?.toString() || "" + }); + } else { + setEditingId(null); + setFormData({ + name: "", price: "", imageSrc: "", imageAlt: "", size: "", color: "", stock: "" + }); + } + setIsFormOpen(true); + }; + + const handleCloseForm = () => { + setIsFormOpen(false); + setEditingId(null); + }; + + const handleInputChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData(prev => ({ + ...prev, + [name]: value + })); + }; + + const handleSaveProduct = () => { + if (!formData.name || !formData.price) { + alert("Please fill in required fields"); + return; + } + + if (editingId) { + setProducts(products.map(p => + p.id === editingId + ? { + ...p, + name: formData.name, + price: formData.price, + imageSrc: formData.imageSrc, + imageAlt: formData.imageAlt, + size: formData.size, + color: formData.color, + stock: parseInt(formData.stock) || 0 + } + : p + )); + } else { + const newProduct: Product = { + id: Date.now().toString(), + name: formData.name, + price: formData.price, + imageSrc: formData.imageSrc, + imageAlt: formData.imageAlt, + size: formData.size, + color: formData.color, + stock: parseInt(formData.stock) || 0 + }; + setProducts([...products, newProduct]); + } + handleCloseForm(); + }; + + const handleDeleteProduct = (id: string) => { + if (confirm("Are you sure you want to delete this product?")) { + setProducts(products.filter(p => p.id !== id)); + } + }; + + return ( + + + +
+
+
+

Admin Panel

+

Manage your clothing inventory

+
+ + {/* Add Product Button */} + + + {/* Products Table */} +
+
+ + + + + + + + + + + + + {products.map((product) => ( + + + + + + + + + ))} + +
Product NamePriceSizeColorStockActions
{product.name}{product.price}{product.size || "-"}{product.color || "-"}{product.stock || 0} +
+ + +
+
+
+
+
+
+ + {/* Modal Form */} + {isFormOpen && ( +
+
+
+

+ {editingId ? "Edit Product" : "Add New Product"} +

+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ +
+ + +
+
+
+ )} +
+ ); +}