1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| "use client" import { InferResponseType } from "hono"; import { ColumnDef } from "@tanstack/react-table"; import { ArrowUpDown } from "lucide-react"; import { format } from "date-fns";
import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Badge } from "@/components/ui/badge";
import { Actions } from "./actions"; import { client } from "@/lib/hono"; import { formatCurrency } from "@/lib/utils"; import { AccountColumn } from "./account-column"; import { CategoryColumn } from "./category-column";
export type ResponsType = InferResponseType<typeof client.api.transactions.$get, 200>["data"][0];
export const columns: ColumnDef<ResponsType>[] = [ { id: "select", header: ({ table }) => ( <Checkbox checked={ table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && "indeterminate") } onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row }) => ( <Checkbox checked={row.getIsSelected()} onCheckedChange={(value) => row.toggleSelected(!!value)} aria-label="Select row" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "date", header: ({ column }) => { return ( <Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")} > Date <ArrowUpDown className="ml-2 h-4 w-4" /> </Button> ) }, cell: ({ row }) => { const date = row.getValue("date") as Date;
return ( <span> {format(date, "dd MMMM,yyyy")} </span> ) } }, { accessorKey: "category", header: ({ column }) => { return ( <Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")} > Category <ArrowUpDown className="ml-2 h-4 w-4" /> </Button> ) }, cell: ({ row }) => { return ( <CategoryColumn id = {row.original.id} category={row.original.category} categoryId={row.original.categoryId} /> ); } }, { accessorKey: "payee", header: ({ column }) => { return ( <Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")} > Payee <ArrowUpDown className="ml-2 h-4 w-4" /> </Button> ) } }, { accessorKey: "amount", header: ({ column }) => { return ( <Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")} > Amount <ArrowUpDown className="ml-2 h-4 w-4" /> </Button> ) }, cell: ({ row }) => { const amount = parseFloat(row.getValue("amount"));
return ( <Badge variant={amount > 0 ? "primary" : "destructive"} className="text-xs font-medium px-3.5 py-2.5" > {formatCurrency(amount)} </Badge> ) } }, { accessorKey: "account", header: ({ column }) => { return ( <Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")} > Account <ArrowUpDown className="ml-2 h-4 w-4" /> </Button> ) }, cell: ({ row }) => { return ( <AccountColumn account= { row.original.account} accountId = { row.original.accountId } /> ) } }, { id: "actions", cell: ({ row }) => <Actions id={row.original.id} /> } ]
|