diff --git a/src/components/stock/AddItemForm.tsx b/src/components/stock/AddItemForm.tsx new file mode 100644 index 0000000..9e8ddd2 --- /dev/null +++ b/src/components/stock/AddItemForm.tsx @@ -0,0 +1,120 @@ +"use client" + +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import * as z from "zod" + +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { showSuccess } from "@/utils/toast" + +const formSchema = z.object({ + name: z.string().min(2, { message: "Name must be at least 2 characters." }), + sku: z.string().min(2, { message: "SKU must be at least 2 characters." }), + category: z.string().min(2, { message: "Category must be at least 2 characters." }), + quantity: z.coerce.number().int().positive({ message: "Quantity must be a positive number." }), + price: z.coerce.number().positive({ message: "Price must be a positive number." }), +}) + +export function AddItemForm({ setOpen }: { setOpen: (open: boolean) => void }) { + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + name: "", + sku: "", + category: "", + quantity: 1, + price: 0.00, + }, + }) + + function onSubmit(values: z.infer) { + // In a real app, you'd send this to your API + console.log(values) + showSuccess("New item added successfully!") + setOpen(false) // Close the dialog on successful submission + } + + return ( +
+ + ( + + Item Name + + + + + + )} + /> + ( + + SKU + + + + + + )} + /> + ( + + Category + + + + + + )} + /> +
+ ( + + Quantity + + + + + + )} + /> + ( + + Price + + + + + + )} + /> +
+ + + + ) +} \ No newline at end of file diff --git a/src/components/stock/columns.tsx b/src/components/stock/columns.tsx index c0cdcbf..315b40b 100644 --- a/src/components/stock/columns.tsx +++ b/src/components/stock/columns.tsx @@ -31,8 +31,11 @@ export const columns: ColumnDef[] = [ header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" diff --git a/src/pages/StockList.tsx b/src/pages/StockList.tsx index 62e59ca..8838972 100644 --- a/src/pages/StockList.tsx +++ b/src/pages/StockList.tsx @@ -1,7 +1,17 @@ +import { useState } from "react" import { columns, StockItem } from "../components/stock/columns" import { DataTable } from "../components/stock/data-table" import { Button } from "@/components/ui/button" import { PlusCircle } from "lucide-react" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { AddItemForm } from "../components/stock/AddItemForm" // In a real app, you would fetch this data from an API. const data: StockItem[] = [ @@ -71,6 +81,8 @@ const data: StockItem[] = [ ]; const StockList = () => { + const [open, setOpen] = useState(false); + return (
@@ -78,10 +90,23 @@ const StockList = () => {

Stock List

Manage your inventory here.

- + + + + + + + Add New Stock Item + + Fill in the details below to add a new item to your inventory. + + + + +