95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
"use client"
|
||
|
||
import { ColumnDef, HeaderContext, CellContext } from "@tanstack/react-table"
|
||
import { User } from "@/types/user"
|
||
import { Badge } from "@/components/ui/badge"
|
||
import { Check, X } from "lucide-react"
|
||
import { Button } from "@/components/ui/button"
|
||
import { ArrowUpDown } from "lucide-react"
|
||
|
||
// Actions cell component will be added later or inline if simple
|
||
import { DataTableRowActions } from "./user-row-actions"
|
||
|
||
export const getColumns = (onRefresh: () => void): ColumnDef<User>[] => [
|
||
{
|
||
accessorKey: "id",
|
||
header: ({ column }: HeaderContext<User, unknown>) => {
|
||
return (
|
||
<Button
|
||
variant="ghost"
|
||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||
>
|
||
ID
|
||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||
</Button>
|
||
)
|
||
},
|
||
},
|
||
{
|
||
accessorKey: "username",
|
||
header: ({ column }: HeaderContext<User, unknown>) => {
|
||
return (
|
||
<Button
|
||
variant="ghost"
|
||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||
>
|
||
Kullanıcı Adı
|
||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||
</Button>
|
||
)
|
||
},
|
||
},
|
||
{
|
||
accessorKey: "email",
|
||
header: ({ column }: HeaderContext<User, unknown>) => {
|
||
return (
|
||
<Button
|
||
variant="ghost"
|
||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||
>
|
||
Email
|
||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||
</Button>
|
||
)
|
||
},
|
||
},
|
||
{
|
||
accessorKey: "email_verified",
|
||
header: "Doğrulandı",
|
||
cell: ({ row }: CellContext<User, unknown>) => {
|
||
return row.getValue("email_verified") ? (
|
||
<Badge variant="secondary" className="bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300"><Check className="w-3 h-3 mr-1" /> Evet</Badge>
|
||
) : (
|
||
<Badge variant="outline" className="text-gray-500"><X className="w-3 h-3 mr-1" /> Hayır</Badge>
|
||
)
|
||
},
|
||
},
|
||
{
|
||
accessorKey: "deleted_at",
|
||
header: "Durum",
|
||
cell: ({ row }) => {
|
||
const deletedAt = row.original.deleted_at
|
||
return deletedAt ? (
|
||
<Badge variant="destructive">Silindi</Badge>
|
||
) : (
|
||
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">Aktif</Badge>
|
||
)
|
||
}
|
||
},
|
||
{
|
||
accessorKey: "is_admin",
|
||
header: "Rol",
|
||
cell: ({ row }: CellContext<User, unknown>) => {
|
||
return row.getValue("is_admin") ? (
|
||
<Badge variant="default">Admin</Badge>
|
||
) : (
|
||
<Badge variant="secondary">User</Badge>
|
||
)
|
||
},
|
||
},
|
||
{
|
||
id: "actions",
|
||
cell: ({ row }: CellContext<User, unknown>) => <DataTableRowActions row={row} onRefresh={onRefresh} />,
|
||
},
|
||
]
|