202 lines
5.3 KiB
TypeScript
202 lines
5.3 KiB
TypeScript
"use client"
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip"
|
|
|
|
import {
|
|
ColumnDef,
|
|
} from "@tanstack/react-table"
|
|
import { Eye, SquarePen, Trash2 } from "lucide-react"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
import { Checkbox } from "@/components/ui/checkbox"
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
|
import { Badge } from "@/components/ui/badge"
|
|
import { cn } from "@/lib/utils";
|
|
|
|
export type DataProps = {
|
|
id: string | number;
|
|
order: number;
|
|
customer: {
|
|
name: string;
|
|
image: string;
|
|
};
|
|
date: string;
|
|
quantity: number;
|
|
amount: string;
|
|
status: "paid" | "due" | "canceled";
|
|
action: React.ReactNode;
|
|
}
|
|
export const columns: ColumnDef<DataProps>[] = [
|
|
{
|
|
id: "select",
|
|
header: ({ table }) => (
|
|
<Checkbox
|
|
checked={
|
|
table.getIsAllPageRowsSelected() ||
|
|
(table.getIsSomePageRowsSelected() && "indeterminate")
|
|
}
|
|
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
|
aria-label="Select all"
|
|
/>
|
|
),
|
|
cell: ({ row }) => (
|
|
<div className="xl:w-16">
|
|
<Checkbox
|
|
checked={row.getIsSelected()}
|
|
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
aria-label="Select row"
|
|
/>
|
|
</div>
|
|
),
|
|
enableSorting: false,
|
|
enableHiding: false,
|
|
},
|
|
{
|
|
accessorKey: "id",
|
|
header: "id",
|
|
cell: ({ row }) => <span>{row.getValue("id")}</span>,
|
|
},
|
|
{
|
|
accessorKey: "order",
|
|
header: "Order",
|
|
cell: ({ row }) => <span>{row.getValue("order")}</span>,
|
|
},
|
|
{
|
|
accessorKey: "customer",
|
|
header: "Customer",
|
|
cell: ({ row }) => {
|
|
const user = row.original.customer;
|
|
return (
|
|
<div className="font-medium text-card-foreground/80">
|
|
<div className="flex gap-3 items-center">
|
|
<Avatar
|
|
className="rounded-full w-8 h-8"
|
|
>
|
|
{user?.image ? (
|
|
<AvatarImage src={user.image} />
|
|
) : (
|
|
<AvatarFallback>AB</AvatarFallback>
|
|
)}
|
|
</Avatar>
|
|
<span className="text-sm text-default-600 whitespace-nowrap">
|
|
{user?.name ?? "Unknown User"}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "date",
|
|
header: "Date",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<span>{row.getValue("date")}</span>
|
|
)
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "quantity",
|
|
header: "Quantity",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<span>{row.getValue("quantity")}</span>
|
|
)
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "amount",
|
|
header: "Amount",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<span>{row.getValue("amount")}</span>
|
|
)
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: "Status",
|
|
cell: ({ row }) => {
|
|
const statusColors: Record<string, string> = {
|
|
paid: "bg-success/20 text-success",
|
|
due: "bg-warning/20 text-warning",
|
|
canceled: "bg-destructive/20 text-destructive"
|
|
};
|
|
const status = row.getValue<string>("status");
|
|
const statusStyles = statusColors[status] || "default";
|
|
return (
|
|
<Badge
|
|
className={cn("rounded-full px-5", statusStyles)}
|
|
>{status} </Badge>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
id: "actions",
|
|
accessorKey: "action",
|
|
header: "Action",
|
|
enableHiding: false,
|
|
cell: ({ row }) => {
|
|
return (
|
|
<div className="flex items-center gap-2">
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="w-7 h-7 ring-offset-transparent border-default-300 text-default-500"
|
|
color="secondary"
|
|
>
|
|
<Eye className="w-4 h-4" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">
|
|
<p>View</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="w-7 h-7 ring-offset-transparent border-default-300 text-default-500"
|
|
color="secondary"
|
|
>
|
|
<SquarePen className="w-4 h-4" />
|
|
</Button>
|
|
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">
|
|
<p>Edit</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="w-7 h-7 ring-offset-transparent border-default-300 text-default-500"
|
|
color="secondary"
|
|
>
|
|
<Trash2 className="w-4 h-4" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top" className="bg-destructive text-destructive-foreground">
|
|
<p>Delete</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
] |