aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/routes/admin.users.tsx
blob: c403285fd48b5fb1cc18f571cc0c8e3ee40a9fd2 (plain)
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
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { adminApiGetUsers } from "../.server/api/client";
import { ensureAdminUserLoggedIn } from "../.server/auth";

export const meta: MetaFunction = () => [
	{ title: "[Admin] Users | iOSDC Japan 2024 Albatross.swift" },
];

export async function loader({ request }: LoaderFunctionArgs) {
	const { token } = await ensureAdminUserLoggedIn(request);
	const { users } = await adminApiGetUsers(token);
	return { users };
}

export default function AdminUsers() {
	const { users } = useLoaderData<typeof loader>()!;

	return (
		<div>
			<div>
				<h1>[Admin] Users</h1>
				<ul>
					{users.map((user) => (
						<li key={user.user_id}>
							{user.display_name} (id={user.user_id} username={user.username})
							{user.is_admin && <span> admin</span>}
						</li>
					))}
				</ul>
			</div>
		</div>
	);
}