Files
app/frontend/src/routes/_layout/admin.tsx
T
Melvin Strobl 8be7f9770e Vendor backend and frontend into the monorepo
The submodule collapse was only half applied: .gitmodules was deleted but
backend/ and frontend/ were still recorded as gitlinks, so none of their
files were tracked. Replace the gitlinks with the real trees.

Also untrack .env (it carried placeholder secrets) in favour of a tracked
.env.example, drop the committed __pycache__, and narrow the blanket *.png
ignore that would have swallowed design assets.
2026-08-09 15:14:54 +02:00

74 lines
1.8 KiB
TypeScript

import { useSuspenseQuery } from "@tanstack/react-query"
import { createFileRoute, redirect } 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,
beforeLoad: async () => {
const user = await UsersService.readUserMe()
if (!user.is_superuser) {
throw redirect({
to: "/",
})
}
},
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>
)
}