aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/routes/admin.games.tsx
blob: 00a56d63b7913b7ce53c235adfc2aa0e520d68c6 (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
35
36
37
38
39
40
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData, Link } from "@remix-run/react";
import { isAuthenticated } from "../.server/auth";
import { adminApiGetGames } from "../.server/api/client";

export const meta: MetaFunction = () => {
  return [{ title: "[Admin] Games | iOSDC Japan 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 { games } = await adminApiGetGames(token);
  return { 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>
  );
}