From 2385e1832fa0acc98fd285453701d5e829670955 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Wed, 31 Jul 2024 01:35:29 +0900
Subject: feat: implement /admin/users page

---
 frontend/app/routes/admin.users.tsx | 48 +++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 frontend/app/routes/admin.users.tsx

(limited to 'frontend/app/routes/admin.users.tsx')

diff --git a/frontend/app/routes/admin.users.tsx b/frontend/app/routes/admin.users.tsx
new file mode 100644
index 0000000..d9901a2
--- /dev/null
+++ b/frontend/app/routes/admin.users.tsx
@@ -0,0 +1,48 @@
+import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
+import { useLoaderData } from "@remix-run/react";
+import { isAuthenticated } from "../.server/auth";
+import { apiClient } from "../.server/api/client";
+
+export const meta: MetaFunction = () => {
+  return [{ title: "[Admin] Users | iOSDC 2024 Albatross.swift" }];
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+  const { user, token } = await isAuthenticated(request, {
+    failureRedirect: "/login",
+  });
+  if (!user.is_admin) {
+    throw new Error("Unauthorized");
+  }
+  const { data, error } = await apiClient.GET("/admin/users", {
+    params: {
+      header: {
+        Authorization: `Bearer ${token}`,
+      },
+    },
+  });
+  if (error) {
+    throw new Error(error.message);
+  }
+  return { users: data.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} (uid={user.user_id} username={user.username})
+              {user.is_admin && <span> admin</span>}
+            </li>
+          ))}
+        </ul>
+      </div>
+    </div>
+  );
+}
-- 
cgit v1.2.3-70-g09d2

