diff --git a/frontend/static/js/api/tournament/tournaments.js b/frontend/static/js/api/tournament/tournaments.js
index 149f73d..8fb0489 100644
--- a/frontend/static/js/api/tournament/tournaments.js
+++ b/frontend/static/js/api/tournament/tournaments.js
@@ -22,16 +22,8 @@ class Tourmanents
return tournament;
}
- /**
- * @param {boolean} online if the tournament is online or offline
- */
- async createTournament(nb_players, nb_players_by_game, name = "", online = true)
+ async createTournament(nb_players, nb_players_by_game, name = "")
{
- if (online === false)
- {
- let tournament = new Tourmanent(this.client, nb_players, nb_players_by_game, 5, false, false, [], 0);
- return tournament;
- }
let response = await this.client._post("/api/tournaments/", {nb_players: nb_players, nb_players_by_game: nb_players_by_game, name: name});
if (response.status === 403)
@@ -41,10 +33,7 @@ class Tourmanents
}
let response_data = await response.json();
-
- let tournament = this.getTournament(response_data["id"]);
-
- return tournament;
+ return response_data;
}
/**
diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js
index 1bd8f6e..db5c608 100644
--- a/frontend/static/js/index.js
+++ b/frontend/static/js/index.js
@@ -16,6 +16,7 @@ import ProfilePageView from "./views/ProfilePageView.js";
import MatchMakingView from "./views/MatchMakingView.js";
import TournamentPageView from "./views/TournamentPageView.js";
import TournamentsView from "./views/TournamentsListView.js";
+import TournamentCreateView from "./views/TournamentCreateView.js";
let client = new Client(location.protocol + "//" + location.host)
@@ -54,8 +55,9 @@ const router = async (uri) => {
const routes = [
{ path: "/", view: Dashboard },
{ path: "/profiles/:id", view: ProfilePageView },
+ { path: "/tournaments/create", view: TournamentCreateView },
{ path: "/tournaments/:id", view: TournamentPageView },
- { path: "/tournaments/", view: TournamentsView},
+ { path: "/tournaments/", view: TournamentsView },
{ path: "/login", view: LoginView },
{ path: "/logout", view: LogoutView },
{ path: "/register", view: RegisterView },
diff --git a/frontend/static/js/views/TournamentCreateView.js b/frontend/static/js/views/TournamentCreateView.js
new file mode 100644
index 0000000..ef93428
--- /dev/null
+++ b/frontend/static/js/views/TournamentCreateView.js
@@ -0,0 +1,52 @@
+import {client, navigateTo} from "../index.js";
+import { clear, fill_errors } from "../utils/formUtils.js";
+import AbstractAuthentifiedView from "./abstracts/AbstractAuthentifiedView.js";
+
+export default class extends AbstractAuthentifiedView
+{
+ constructor(params)
+ {
+ super(params, "Create tournament");
+ this.id = params.id;
+ }
+
+ async create()
+ {
+ let name = document.getElementById("name-input").value;
+ let nb_players = document.getElementById("nb_players-input").value;
+ let nb_players_by_game = document.getElementById("nb_players_by_game-input").value
+
+ let response_data = await client.tournaments.createTournament(nb_players, nb_players_by_game, name);
+
+ if (response_data === null)
+ return;
+
+ let id = response_data["id"]
+ if (id !== undefined)
+ {
+ navigateTo(`/tournaments/${id}`);
+ return;
+ }
+
+ clear("innerHTML", ["name", "nb_players", "nb_players_by_game"]);
+ fill_errors(response_data, "innerHTML");
+ }
+
+ async postInit()
+ {
+ document.getElementById("create-button").onclick = this.create;
+ }
+
+ async getHtml()
+ {
+ return `
+
+
+
+
+
+
+
+ `
+ }
+}