Spaces:
Build error
Build error
Download components/AdminPanel.jsx from saytowork/anycoder-a25f751f: direct link, hf CLI and curl.
- Browser
- Download file 9.01 kB
-
https://huggingface.co/spaces/saytowork/anycoder-a25f751f/resolve/main/components/AdminPanel.jsx
- Command line
-
hf download hf://spaces/saytowork/anycoder-a25f751f/components/AdminPanel.jsx
-
curl -L -o AdminPanel.jsx https://huggingface.co/spaces/saytowork/anycoder-a25f751f/resolve/main/components/AdminPanel.jsx
9.01 kB
| import { motion } from 'framer-motion'; | |
| import { Plus, X, Save, Package } from 'lucide-react'; | |
| import { useState } from 'react'; | |
| import { useStore } from '../store/useStore'; | |
| export default function AdminPanel() { | |
| const { products, addProduct, updateProduct, deleteProduct } = useStore(); | |
| const [isFormOpen, setIsFormOpen] = useState(false); | |
| const [editingProduct, setEditingProduct] = useState(null); | |
| const [formData, setFormData] = useState({ | |
| name: '', | |
| brand: '', | |
| price: '', | |
| stock: '', | |
| image: '', | |
| description: '' | |
| }); | |
| const handleSubmit = (e) => { | |
| e.preventDefault(); | |
| const productData = { | |
| ...formData, | |
| price: parseFloat(formData.price), | |
| stock: parseInt(formData.stock), | |
| id: editingProduct ? editingProduct.id : Date.now(), | |
| }; | |
| if (editingProduct) { | |
| updateProduct(productData); | |
| } else { | |
| addProduct(productData); | |
| } | |
| resetForm(); | |
| }; | |
| const handleEdit = (product) => { | |
| setEditingProduct(product); | |
| setFormData(product); | |
| setIsFormOpen(true); | |
| }; | |
| const resetForm = () => { | |
| setFormData({ | |
| name: '', | |
| brand: '', | |
| price: '', | |
| stock: '', | |
| image: '', | |
| description: '' | |
| }); | |
| setEditingProduct(null); | |
| setIsFormOpen(false); | |
| }; | |
| return ( | |
| <div className="min-h-screen pt-24 px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto"> | |
| <div className="flex justify-between items-center mb-8"> | |
| <div> | |
| <h1 className="text-4xl font-serif font-bold text-white mb-2">Inventory Management</h1> | |
| <p className="text-gray-400">Manage your luxury timepiece collection</p> | |
| </div> | |
| <motion.button | |
| whileHover={{ scale: 1.05 }} | |
| whileTap={{ scale: 0.95 }} | |
| onClick={() => setIsFormOpen(true)} | |
| className="flex items-center gap-2 bg-gold-500 text-midnight px-6 py-3 rounded-full font-bold hover:bg-gold-400 transition-colors" | |
| > | |
| <Plus className="w-5 h-5" /> | |
| Add Product | |
| </motion.button> | |
| </div> | |
| {/* Product Grid */} | |
| <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 mb-12"> | |
| {products.map((product) => ( | |
| <motion.div | |
| key={product.id} | |
| layout | |
| initial={{ opacity: 0 }} | |
| animate={{ opacity: 1 }} | |
| className="bg-white/5 border border-white/10 rounded-2xl p-5" | |
| > | |
| <div className="flex items-start justify-between mb-4"> | |
| <div className="w-16 h-16 rounded-lg overflow-hidden bg-gray-800"> | |
| <img src={product.image} alt={product.name} className="w-full h-full object-cover" /> | |
| </div> | |
| <div className="flex gap-2"> | |
| <button | |
| onClick={() => handleEdit(product)} | |
| className="p-2 text-blue-400 hover:bg-blue-400/10 rounded-lg transition-colors" | |
| > | |
| <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg> | |
| </button> | |
| <button | |
| onClick={() => deleteProduct(product.id)} | |
| className="p-2 text-red-400 hover:bg-red-400/10 rounded-lg transition-colors" | |
| > | |
| <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg> | |
| </button> | |
| </div> | |
| </div> | |
| <h3 className="text-white font-semibold truncate">{product.name}</h3> | |
| <div className="flex justify-between items-center mt-2"> | |
| <span className="text-gold-400 font-bold">${product.price.toLocaleString()}</span> | |
| <span className={`text-sm ${product.stock < 5 ? 'text-red-400' : 'text-gray-400'}`}> | |
| {product.stock} in stock | |
| </span> | |
| </div> | |
| </motion.div> | |
| ))} | |
| </div> | |
| {/* Product Form Modal */} | |
| <AnimatePresence> | |
| {isFormOpen && ( | |
| <> | |
| <motion.div | |
| initial={{ opacity: 0 }} | |
| animate={{ opacity: 1 }} | |
| exit={{ opacity: 0 }} | |
| onClick={resetForm} | |
| className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50" | |
| /> | |
| <motion.div | |
| initial={{ opacity: 0, scale: 0.9 }} | |
| animate={{ opacity: 1, scale: 1 }} | |
| exit={{ opacity: 0, scale: 0.9 }} | |
| className="fixed inset-0 z-50 flex items-center justify-center p-4" | |
| > | |
| <div className="bg-midnight border border-white/10 rounded-2xl w-full max-w-lg p-8 relative"> | |
| <button | |
| onClick={resetForm} | |
| className="absolute top-4 right-4 text-gray-400 hover:text-white" | |
| > | |
| <X className="w-6 h-6" /> | |
| </button> | |
| <h2 className="text-2xl font-serif font-bold text-white mb-6"> | |
| {editingProduct ? 'Edit Product' : 'Add New Product'} | |
| </h2> | |
| <form onSubmit={handleSubmit} className="space-y-4"> | |
| <div> | |
| <label className="block text-sm text-gray-400 mb-1">Product Name</label> | |
| <input | |
| type="text" | |
| required | |
| value={formData.name} | |
| onChange={(e) => setFormData({ ...formData, name: e.target.value })} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white focus:border-gold-500 focus:outline-none" | |
| /> | |
| </div> | |
| <div className="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label className="block text-sm text-gray-400 mb-1">Brand</label> | |
| <input | |
| type="text" | |
| required | |
| value={formData.brand} | |
| onChange={(e) => setFormData({ ...formData, brand: e.target.value })} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white focus:border-gold-500 focus:outline-none" | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm text-gray-400 mb-1">Price ($)</label> | |
| <input | |
| type="number" | |
| required | |
| step="0.01" | |
| value={formData.price} | |
| onChange={(e) => setFormData({ ...formData, price: e.target.value })} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white focus:border-gold-500 focus:outline-none" | |
| /> | |
| </div> | |
| </div> | |
| <div> | |
| <label className="block text-sm text-gray-400 mb-1">Stock Quantity</label> | |
| <input | |
| type="number" | |
| required | |
| value={formData.stock} | |
| onChange={(e) => setFormData({ ...formData, stock: e.target.value })} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white focus:border-gold-500 focus:outline-none" | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-sm text-gray-400 mb-1">Image URL</label> | |
| <input | |
| type="url" | |
| required | |
| value={formData.image} | |
| onChange={(e) => setFormData({ ...formData, image: e.target.value })} | |
| className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white focus:border-gold-500 focus:outline-none" | |
| /> | |
| </div> | |
| <button | |
| type="submit" | |
| className="w-full bg-gradient-to-r from-gold-500 to-gold-600 text-midnight font-bold py-4 rounded-xl hover:shadow-lg hover:shadow-gold-500/25 transition-all flex items-center justify-center gap-2" | |
| > | |
| <Save className="w-5 h-5" /> | |
| {editingProduct ? 'Update Product' : 'Add Product'} | |
| </button> | |
| </form> | |
| </div> | |
| </motion.div> | |
| </> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| ); | |
| } |