diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-31 22:20:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-31 22:20:35 +0900 |
| commit | 4aff0feca72da0175dcecb44aca9b3e30c861bc5 (patch) | |
| tree | 253a3094f3606682982b91b9be7a03f1e4b3f723 /frontend/app/routes/admin.games.tsx | |
| parent | 715651d6d263c5f526e8e13a8e2bb032193c5218 (diff) | |
| parent | 3840c6d8e4261f182657b11ba55f61da04d70b28 (diff) | |
| download | phperkaigi-2025-albatross-4aff0feca72da0175dcecb44aca9b3e30c861bc5.tar.gz phperkaigi-2025-albatross-4aff0feca72da0175dcecb44aca9b3e30c861bc5.tar.zst phperkaigi-2025-albatross-4aff0feca72da0175dcecb44aca9b3e30c861bc5.zip | |
Merge branch 'feat/admin-games-page'
Diffstat (limited to 'frontend/app/routes/admin.games.tsx')
| -rw-r--r-- | frontend/app/routes/admin.games.tsx | 49 |
1 files changed, 49 insertions, 0 deletions
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> + ); +} |
