[dyad] Added barcode generation and viewing - wrote 4 file(s), added react-barcode package(s)
This commit is contained in:
parent
0a64761eec
commit
dce3f15acc
4 changed files with 94 additions and 26 deletions
|
|
@ -50,6 +50,7 @@
|
|||
"lucide-react": "^0.462.0",
|
||||
"next-themes": "^0.3.0",
|
||||
"react": "^18.3.1",
|
||||
"react-barcode": "^1.6.1",
|
||||
"react-day-picker": "^8.10.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.53.0",
|
||||
|
|
|
|||
|
|
@ -125,6 +125,9 @@ importers:
|
|||
react:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1
|
||||
react-barcode:
|
||||
specifier: ^1.6.1
|
||||
version: 1.6.1(react@18.3.1)
|
||||
react-day-picker:
|
||||
specifier: ^8.10.1
|
||||
version: 8.10.1(date-fns@3.6.0)(react@18.3.1)
|
||||
|
|
@ -1886,6 +1889,9 @@ packages:
|
|||
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
|
||||
hasBin: true
|
||||
|
||||
jsbarcode@3.12.1:
|
||||
resolution: {integrity: sha512-QZQSqIknC2Rr/YOUyOkCBqsoiBAOTYK+7yNN3JsqfoUtJtkazxNw1dmPpxuv7VVvqW13kA3/mKiLq+s/e3o9hQ==}
|
||||
|
||||
json-buffer@3.0.1:
|
||||
resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==}
|
||||
|
||||
|
|
@ -2110,6 +2116,11 @@ packages:
|
|||
queue-microtask@1.2.3:
|
||||
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
||||
|
||||
react-barcode@1.6.1:
|
||||
resolution: {integrity: sha512-pc4ftnO5syHa/UjCruEeRsomlhoxKSugIgTA8T4dH0fvc89UMHL+/1Sp25IAphqG44pJkE5hMXhv89iS09jQyw==}
|
||||
peerDependencies:
|
||||
react: 16 - 19
|
||||
|
||||
react-day-picker@8.10.1:
|
||||
resolution: {integrity: sha512-TMx7fNbhLk15eqcMt+7Z7S2KF7mfTId/XJDjKE8f+IUcFn0l08/kI4FiYTL/0yuOLmEcbR4Fwe3GJf/NiiMnPA==}
|
||||
peerDependencies:
|
||||
|
|
@ -4083,6 +4094,8 @@ snapshots:
|
|||
dependencies:
|
||||
argparse: 2.0.1
|
||||
|
||||
jsbarcode@3.12.1: {}
|
||||
|
||||
json-buffer@3.0.1: {}
|
||||
|
||||
json-schema-traverse@0.4.1: {}
|
||||
|
|
@ -4270,6 +4283,12 @@ snapshots:
|
|||
|
||||
queue-microtask@1.2.3: {}
|
||||
|
||||
react-barcode@1.6.1(react@18.3.1):
|
||||
dependencies:
|
||||
jsbarcode: 3.12.1
|
||||
prop-types: 15.8.1
|
||||
react: 18.3.1
|
||||
|
||||
react-day-picker@8.10.1(date-fns@3.6.0)(react@18.3.1):
|
||||
dependencies:
|
||||
date-fns: 3.6.0
|
||||
|
|
|
|||
33
src/components/stock/BarcodeDialog.tsx
Normal file
33
src/components/stock/BarcodeDialog.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
} from "@/components/ui/dialog"
|
||||
import Barcode from "react-barcode"
|
||||
import { StockItem } from "./columns"
|
||||
|
||||
interface BarcodeDialogProps {
|
||||
item: StockItem | null
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
export const BarcodeDialog = ({ item, open, onOpenChange }: BarcodeDialogProps) => {
|
||||
if (!item) return null
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{item.name}</DialogTitle>
|
||||
<DialogDescription>SKU: {item.sku}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="flex items-center justify-center p-4 bg-white rounded-lg">
|
||||
<Barcode value={item.sku} />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { ColumnDef } from "@tanstack/react-table"
|
||||
import { MoreHorizontal, ArrowUpDown } from "lucide-react"
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ import {
|
|||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { BarcodeDialog } from "./BarcodeDialog"
|
||||
|
||||
export type StockItem = {
|
||||
id: string
|
||||
|
|
@ -32,6 +34,44 @@ const formatCurrency = (price: number) => {
|
|||
}).format(price)
|
||||
}
|
||||
|
||||
const ActionsCell = ({ row }: { row: any }) => {
|
||||
const item = row.original
|
||||
const [isBarcodeOpen, setBarcodeOpen] = React.useState(false)
|
||||
|
||||
return (
|
||||
<>
|
||||
<BarcodeDialog
|
||||
item={item}
|
||||
open={isBarcodeOpen}
|
||||
onOpenChange={setBarcodeOpen}
|
||||
/>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem onClick={() => setBarcodeOpen(true)}>
|
||||
View Barcode
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => navigator.clipboard.writeText(item.id)}
|
||||
>
|
||||
Copy item ID
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem>View details</DropdownMenuItem>
|
||||
<DropdownMenuItem>Edit item</DropdownMenuItem>
|
||||
<DropdownMenuItem className="text-red-600">Delete item</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<StockItem>[] = [
|
||||
{
|
||||
id: "select",
|
||||
|
|
@ -121,31 +161,6 @@ export const columns: ColumnDef<StockItem>[] = [
|
|||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
const item = row.original
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem
|
||||
onClick={() => navigator.clipboard.writeText(item.id)}
|
||||
>
|
||||
Copy item ID
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem>View details</DropdownMenuItem>
|
||||
<DropdownMenuItem>Edit item</DropdownMenuItem>
|
||||
<DropdownMenuItem className="text-red-600">Delete item</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
},
|
||||
cell: ActionsCell,
|
||||
},
|
||||
]
|
||||
Loading…
Reference in a new issue