Sample / app /inventory /page.tsx
SuriRaja's picture
Deploy static build to Hugging Face
b54da4e
"use client"
import { useState } from "react"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Badge } from "@/components/ui/badge"
import { SidebarInset, SidebarTrigger } from "@/components/ui/sidebar"
import { Separator } from "@/components/ui/separator"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Label } from "@/components/ui/label"
import { Plus, Search, Edit, Trash2, Package } from "lucide-react"
import { useToast } from "@/hooks/use-toast"
import Link from "next/link"
const products = [
{
id: 1,
name: "MCB 32A Single Pole",
sku: "MCB-32A-SP",
category: "Circuit Breakers",
brand: "Schneider",
quantity: 25,
price: 520,
status: "In Stock",
},
{
id: 2,
name: "LED Panel Light 40W",
sku: "LED-40W-PNL",
category: "Lighting",
brand: "Philips",
quantity: 8,
price: 1450,
status: "Low Stock",
},
{
id: 3,
name: "Copper Cable 2.5mm²",
sku: "CU-2.5MM-100M",
category: "Cables",
brand: "Havells",
quantity: 450,
price: 95,
status: "In Stock",
},
]
export default function InventoryPage() {
const [searchTerm, setSearchTerm] = useState("")
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
const { toast } = useToast()
const filteredProducts = products.filter(
(product) =>
product.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
product.sku.toLowerCase().includes(searchTerm.toLowerCase()),
)
const handleAddProduct = () => {
toast({ title: "Product Added", description: "New product has been added to inventory" })
setIsAddDialogOpen(false)
}
const handleEdit = (id: number) => {
toast({ title: "Edit Product", description: `Editing product ${id}` })
}
const handleDelete = (id: number) => {
toast({ title: "Product Deleted", description: `Product ${id} has been removed` })
}
return (
<SidebarInset>
<header className="flex h-16 shrink-0 items-center gap-2 px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-2 h-4" />
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link href="/">Dashboard</Link>
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>Inventory</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
</header>
<div className="flex flex-1 flex-col gap-4 p-4">
<div className="flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold">Inventory Management</h1>
<p className="text-muted-foreground">Manage your product inventory</p>
</div>
<Dialog open={isAddDialogOpen} onOpenChange={setIsAddDialogOpen}>
<DialogTrigger asChild>
<Button>
<Plus className="mr-2 h-4 w-4" />
Add Product
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Add New Product</DialogTitle>
<DialogDescription>Enter product details</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="name" className="text-right">
Name
</Label>
<Input id="name" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="sku" className="text-right">
SKU
</Label>
<Input id="sku" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="price" className="text-right">
Price
</Label>
<Input id="price" type="number" className="col-span-3" />
</div>
</div>
<DialogFooter>
<Button onClick={handleAddProduct}>Add Product</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
<Card>
<CardContent className="pt-6">
<div className="relative">
<Search className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search products..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-10"
/>
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Products ({filteredProducts.length})</CardTitle>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Product</TableHead>
<TableHead>SKU</TableHead>
<TableHead>Category</TableHead>
<TableHead>Quantity</TableHead>
<TableHead>Price</TableHead>
<TableHead>Status</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredProducts.map((product) => (
<TableRow key={product.id}>
<TableCell>
<div className="flex items-center space-x-3">
<Package className="h-4 w-4" />
<span className="font-medium">{product.name}</span>
</div>
</TableCell>
<TableCell>{product.sku}</TableCell>
<TableCell>{product.category}</TableCell>
<TableCell>{product.quantity}</TableCell>
<TableCell>₹{product.price}</TableCell>
<TableCell>
<Badge variant={product.status === "In Stock" ? "default" : "secondary"}>{product.status}</Badge>
</TableCell>
<TableCell>
<div className="flex space-x-2">
<Button variant="outline" size="sm" onClick={() => handleEdit(product.id)}>
<Edit className="h-4 w-4" />
</Button>
<Button variant="outline" size="sm" onClick={() => handleDelete(product.id)}>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
</div>
</SidebarInset>
)
}