-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-table-columns.tsx
More file actions
120 lines (117 loc) · 3.27 KB
/
Copy pathdata-table-columns.tsx
File metadata and controls
120 lines (117 loc) · 3.27 KB
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
import AppAvatar from "@/components/avatar";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { StyledLink } from "@/components/ui/link";
import type { ColumnDef } from "@tanstack/react-table";
import { MoreHorizontal } from "lucide-react";
import Link from "next/link";
import { DeleteUserDropdownTrigger } from "./delete";
import { ImpersonateUserDropdownTrigger } from "./impersonate";
import { LogoutUserDevicesDropdownTrigger } from "./logout-devices";
import { UpdateUserDropdownTrigger } from "./update";
export interface User {
id: string;
name: string;
email: string;
avatar?: string | null;
group: { id: string; slug: string };
createdAt: string;
updatedAt: string;
}
export const columns: ColumnDef<User>[] = [
{
accessorKey: "id",
header: "ID",
cell: ({ row }) => {
const user = row.original;
return (
<StyledLink href={`/users/${user.id}`}>
{user.id}
</StyledLink>
);
},
},
{
accessorKey: "name",
header: "姓名",
},
{
accessorKey: "email",
header: "Google 帳號",
},
{
accessorKey: "avatar",
header: "頭貼",
enableSorting: false,
cell: ({ row }) => {
const avatar = row.original.avatar;
const name = row.original.name;
return (
<div className="flex items-center gap-2">
<AppAvatar src={avatar} name={name} />
</div>
);
},
},
{
accessorKey: "group",
header: "群組",
cell: ({ row }) => {
const group = row.original.group;
return <StyledLink href={`/groups/${group.id}`}>{group.slug}</StyledLink>;
},
},
{
accessorKey: "createdAt",
header: "建立時間",
cell: ({ row }) => {
const createdAt = new Date(row.original.createdAt);
return <div>{createdAt.toLocaleString("zh-tw")}</div>;
},
},
{
accessorKey: "updatedAt",
header: "更新時間",
cell: ({ row }) => {
const updatedAt = new Date(row.original.updatedAt);
return <div>{updatedAt.toLocaleString("zh-tw")}</div>;
},
},
{
id: "actions",
cell: ({ row }) => {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">開啟選單</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>動作</DropdownMenuLabel>
<DropdownMenuItem asChild>
<Link href={`/users/${row.original.id}`}>檢視使用者</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<UpdateUserDropdownTrigger id={row.original.id} />
<DeleteUserDropdownTrigger id={row.original.id} />
<DropdownMenuSeparator />
<ImpersonateUserDropdownTrigger
userId={row.original.id}
userName={row.original.name}
/>
<LogoutUserDevicesDropdownTrigger id={row.original.id} />
</DropdownMenuContent>
</DropdownMenu>
);
},
},
];