diff --git a/src/App.scss b/src/App.scss index 831be03..fe08829 100644 --- a/src/App.scss +++ b/src/App.scss @@ -28,6 +28,10 @@ margin: 3px; width: 23% } + .menu-btns.admin .menu-btn{ + width: 32% + } + .menu-btns { margin-top: 25px; @@ -40,6 +44,9 @@ .menu-btn { width: 100% } + .menu-btns.admin .menu-btn{ + width: 100% + } } .login-btn { diff --git a/src/admin/Admin.js b/src/admin/Admin.js new file mode 100644 index 0000000..f7f31e2 --- /dev/null +++ b/src/admin/Admin.js @@ -0,0 +1,84 @@ +import './../App.scss' +import './admin.scss' +import {AdminService} from "../services/AdminService"; +import React, { useState } from "react"; +import { Link } from 'react-router-dom'; +function Admin() { + const [message, setMessage] = useState(true); + const [banId, setBanId] = useState(''); + const [unbanId, setUnbanId] = useState(''); + + const handleSubmitBan = async (e) => { + e.preventDefault(); + + try { + await AdminService.banPlayer(banId) + setMessage('Ban succesful.') + } catch (e) { + setMessage('There was a problem with banning player.') + } + }; + const handleSubmitUnban = async (e) => { + e.preventDefault(); + + try { + await AdminService.unbanPlayer(unbanId) + setMessage('Unban succesful.') + } catch (e) { + setMessage('There was a problem with unbanning player.') + } + }; + return ( +
+

Admin

+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+
+ + setBanId(e.target.value)} + placeholder="Enter username to ban" + maxLength="30" + /> + +
+
+
+
+ + setUnbanId(e.target.value)} + placeholder="Enter username to unban" + maxLength="30" + /> + +
+
+
+

{message}

+
+ ); +} + +export default Admin; diff --git a/src/admin/PlayerBots.js b/src/admin/PlayerBots.js new file mode 100644 index 0000000..4bdfd73 --- /dev/null +++ b/src/admin/PlayerBots.js @@ -0,0 +1,70 @@ +import './../lists/List.scss' +// import DeleteGameButton from './DeleteGameButton'; +import { connect } from 'react-redux'; +import { login, logout } from '../User/store'; +import React, { useState } from "react"; +import {BotService} from "../services/BotService"; +function PlayerGames({ isAuthenticated, user, login, logout }) { + + const [username, setUsername] = useState(''); + const [botsList, setBotsList] = useState([]); + const [message, setMessage] = useState(''); + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + const gl = await BotService.getForPlayer(username); + setBotsList(gl.data.data); + } catch (e) { + setMessage('There was a problem with fetching bot data.'); + } + }; + + return ( +
+

Player Bots

+
+
+ setUsername(e.target.value)} + placeholder="Enter username" + required + /> + +
+ + +
+ +
+
+
+
+ {botsList.map((bot, index) => ( +
+ + {/* */} +
+ ))} +
+
+

{message}

+
+ ); +} + +const mapStateToProps = (state) => ({ + isAuthenticated: state.isAuthenticated, + user: state.user, + }); + +const mapDispatchToProps = {login,logout,}; + +export default connect(mapStateToProps, mapDispatchToProps)(PlayerGames); + + + + diff --git a/src/admin/PlayerGames.js b/src/admin/PlayerGames.js new file mode 100644 index 0000000..5f7fc1b --- /dev/null +++ b/src/admin/PlayerGames.js @@ -0,0 +1,70 @@ +import './../lists/List.scss' +// import DeleteGameButton from './DeleteGameButton'; +import { connect } from 'react-redux'; +import { login, logout } from '../User/store'; +import React, { useState } from "react"; +import {GameService} from "../services/GameService"; +function PlayerGames({ isAuthenticated, user, login, logout }) { + + const [username, setUsername] = useState(''); + const [gamesList, setGamesList] = useState([]); + const [message, setMessage] = useState(''); + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + const gl = await GameService.getAllForPlayer(username); + setGamesList(gl.data.data); + } catch (e) { + setMessage('There was a problem with fetching game data.'); + } + }; + + return ( +
+

Player Games

+
+
+ setUsername(e.target.value)} + placeholder="Enter username" + required + /> + +
+ + +
+ +
+
+
+
+ {gamesList.map((game, index) => ( +
+ + {/* */} +
+ ))} +
+
+

{message}

+
+ ); +} + +const mapStateToProps = (state) => ({ + isAuthenticated: state.isAuthenticated, + user: state.user, + }); + +const mapDispatchToProps = {login,logout,}; + +export default connect(mapStateToProps, mapDispatchToProps)(PlayerGames); + + + + diff --git a/src/admin/PlayerTournaments.js b/src/admin/PlayerTournaments.js new file mode 100644 index 0000000..a6f1ab0 --- /dev/null +++ b/src/admin/PlayerTournaments.js @@ -0,0 +1,70 @@ +import './../lists/List.scss' +// import DeleteGameButton from './DeleteGameButton'; +import { connect } from 'react-redux'; +import { login, logout } from '../User/store'; +import React, { useState } from "react"; +import {TournamentService} from "../services/TournamentService"; +function PlayerGames({ isAuthenticated, user, login, logout }) { + + const [username, setUsername] = useState(''); + const [gamesList, setGamesList] = useState([]); + const [message, setMessage] = useState(''); + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + const gl = await TournamentService.getForPlayer(username); + setGamesList(gl.data.data); + } catch (e) { + setMessage('There was a problem with fetching tournament data.'); + } + }; + + return ( +
+

Player Tournaments

+
+
+ setUsername(e.target.value)} + placeholder="Enter username" + required + /> + +
+ + +
+ +
+
+
+
+ {gamesList.map((game, index) => ( +
+ + {/* */} +
+ ))} +
+
+

{message}

+
+ ); +} + +const mapStateToProps = (state) => ({ + isAuthenticated: state.isAuthenticated, + user: state.user, + }); + +const mapDispatchToProps = {login,logout,}; + +export default connect(mapStateToProps, mapDispatchToProps)(PlayerGames); + + + + diff --git a/src/admin/admin.scss b/src/admin/admin.scss new file mode 100644 index 0000000..522c8c7 --- /dev/null +++ b/src/admin/admin.scss @@ -0,0 +1,19 @@ +.ban-container{ + display: flex; + justify-content: space-around; + margin-top: 50px; + + .ban-form{ + flex-basis: 45%; + + input{ + width:100%; + } + } + +} +@media only screen and (max-width: 650px) { + .ban-container{ + flex-direction: column; + } +} diff --git a/src/index.js b/src/index.js index ab909e4..c9e4144 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,10 @@ import EditTournamentForm from "./forms/EditTournamentForm"; import TournamentDetails from "./Tournaments/TournamentDetails"; import ProfileView from "./User/ProfileView/ProfileView"; import About from "./about.js"; +import Admin from "./admin/Admin"; +import PlayerBots from "./admin/PlayerBots"; +import PlayerGames from "./admin/PlayerGames"; +import PlayerTournaments from "./admin/PlayerTournaments"; import Leaderboard from "./Tournaments/leaderboard.js"; import TournamentsHelp from "./Tournaments/TournamentsHelp"; import TournamentsLeaderboard from "./Tournaments/TournamentsLeaderboard"; @@ -93,6 +97,23 @@ const router = createBrowserRouter([ path: "/leaderboard", element: , }, + { + path: "/admin", + element: , + }, + { + path: "/admin/PlayerBots", + element: , + }, + { + path: "/admin/PlayerGames", + element: , + }, + { + path: "/admin/PlayerTournaments", + element: , + }, + ]); const root = ReactDOM.createRoot(document.getElementById('root')); diff --git a/src/services/AdminService.js b/src/services/AdminService.js new file mode 100644 index 0000000..420bd9d --- /dev/null +++ b/src/services/AdminService.js @@ -0,0 +1,18 @@ +import { Api } from './Api' +export const AdminService = { + + banPlayer: async function (id) { + try { + return await Api.put(`Administrative/banPlayer?playerId=${id}`); + } catch(e) { + return Api.processError(e) + } + }, + unbanPlayer: async function (id) { + try { + return await Api.put(`Administrative/unbanPlayer?playerId=${id}`); + } catch(e) { + return Api.processError(e) + } + }, +} \ No newline at end of file diff --git a/src/services/BotService.js b/src/services/BotService.js new file mode 100644 index 0000000..d29082c --- /dev/null +++ b/src/services/BotService.js @@ -0,0 +1,11 @@ +import { Api } from './Api' +export const BotService = { + + getForPlayer: async function (login) { + try { + return await Api.get(`Bot/getForPlayer?playerName=${login}`) + } catch(e) { + return Api.processError(e) + } + }, +} \ No newline at end of file diff --git a/src/services/GameService.js b/src/services/GameService.js index 9a891e9..062c693 100644 --- a/src/services/GameService.js +++ b/src/services/GameService.js @@ -31,6 +31,13 @@ export const GameService = { return Api.processError(e) } }, + getAllForPlayer: async function (login) { + try { + return await Api.get(`GameType/getAllForPlayer?name=${login}`); + } catch(e) { + return Api.processError(e) + } + }, addGameType: async function (numOfPlayers, gameFile, gameInstructions, interfaceDefinition, isAvaiableForPlay) { try { return await Api.post('GameType/add',{ diff --git a/src/services/TournamentService.js b/src/services/TournamentService.js index 014d34a..2d47d55 100644 --- a/src/services/TournamentService.js +++ b/src/services/TournamentService.js @@ -41,7 +41,15 @@ export const TournamentService = { interfaceDefinition: interfaceDefinition, isAvaiableForPlay: isAvaiableForPlay }) - + } catch(e) { + return Api.processError(e) + } + }, + getForPlayer: async function (login) { + try { + return await Api.post(`Tournament/getFiltered`,{ + creator:login + }) } catch(e) { return Api.processError(e) }