From 3840c6d8e4261f182657b11ba55f61da04d70b28 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Wed, 31 Jul 2024 21:02:40 +0900
Subject: feat: implement /admin/games and /admin/games/{gameId}

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

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

diff --git a/frontend/app/routes/admin.games.tsx b/frontend/app/routes/admin.games.tsx
new file mode 100644
index 0000000..8362c6c
--- /dev/null
+++ b/frontend/app/routes/admin.games.tsx
@@ -0,0 +1,49 @@
+import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
+import { useLoaderData, Link } from "@remix-run/react";
+import { isAuthenticated } from "../.server/auth";
+import { apiClient } from "../.server/api/client";
+
+export const meta: MetaFunction = () => {
+  return [{ title: "[Admin] Games | 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/games", {
+    params: {
+      header: {
+        Authorization: `Bearer ${token}`,
+      },
+    },
+  });
+  if (error) {
+    throw new Error(error.message);
+  }
+  return { games: data.games };
+}
+
+export default function AdminGames() {
+  const { games } = useLoaderData<typeof loader>()!;
+
+  return (
+    <div>
+      <div>
+        <h1>[Admin] Games</h1>
+        <ul>
+          {games.map((game) => (
+            <li key={game.game_id}>
+              <Link to={`/admin/games/${game.game_id}`}>
+                {game.display_name} (id={game.game_id})
+              </Link>
+            </li>
+          ))}
+        </ul>
+      </div>
+    </div>
+  );
+}
-- 
cgit v1.3.1

