-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Expand file tree
/
Copy pathadmin.tsx
More file actions
65 lines (57 loc) · 1.66 KB
/
admin.tsx
File metadata and controls
65 lines (57 loc) · 1.66 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
import { useSuspenseQuery } from "@tanstack/react-query"
import { createFileRoute } from "@tanstack/react-router"
import { Suspense } from "react"
import { type UserPublic, UsersService } from "@/client"
import AddUser from "@/components/Admin/AddUser"
import { columns, type UserTableData } from "@/components/Admin/columns"
import { DataTable } from "@/components/Common/DataTable"
import PendingUsers from "@/components/Pending/PendingUsers"
import useAuth from "@/hooks/useAuth"
function getUsersQueryOptions() {
return {
queryFn: () => UsersService.readUsers({ skip: 0, limit: 100 }),
queryKey: ["users"],
}
}
export const Route = createFileRoute("/_layout/admin")({
component: Admin,
head: () => ({
meta: [
{
title: "Admin - FastAPI Cloud",
},
],
}),
})
function UsersTableContent() {
const { user: currentUser } = useAuth()
const { data: users } = useSuspenseQuery(getUsersQueryOptions())
const tableData: UserTableData[] = users.data.map((user: UserPublic) => ({
...user,
isCurrentUser: currentUser?.id === user.id,
}))
return <DataTable columns={columns} data={tableData} />
}
function UsersTable() {
return (
<Suspense fallback={<PendingUsers />}>
<UsersTableContent />
</Suspense>
)
}
function Admin() {
return (
<div className="flex flex-col gap-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold tracking-tight">Users</h1>
<p className="text-muted-foreground">
Manage user accounts and permissions
</p>
</div>
<AddUser />
</div>
<UsersTable />
</div>
)
}