diff --git a/cypress/e2e/invite.cy.js b/cypress/e2e/invite.cy.js index aff42a15..ab788970 100644 --- a/cypress/e2e/invite.cy.js +++ b/cypress/e2e/invite.cy.js @@ -258,6 +258,8 @@ describe("Invite User into league and change some league Settings and run throug // Makes sure this user actually has points for matchday 2 cy.get(".MuiPagination-ul > :nth-child(3)").click(); cy.get(".MuiTableBody-root > :nth-child(3) > :nth-child(2)").contains("0"); + // Checks if the league settings part is shown + cy.contains("Settings"); // Has all players leave the league cy.contains("Home").click(); cy.contains("Leave League") diff --git a/pages/[league]/index.js b/pages/[league]/index.js index dc3fea5b..43af00dd 100644 --- a/pages/[league]/index.js +++ b/pages/[league]/index.js @@ -24,7 +24,7 @@ import { } from "@mui/material"; // Creates the admin panel -function AdminPanel({ league, notify, leagueName, setLeagueName }) { +function AdminPanel({ league, notify, leagueName, setLeagueName, admin }) { const [startingMoney, setStartingMoney] = useState(150); const [users, setUsers] = useState([]); const [transfers, setTransfers] = useState(6); @@ -47,146 +47,158 @@ function AdminPanel({ league, notify, leagueName, setLeagueName }) { useEffect(() => { updateData(league); }, [league]); - return ( - <> -

Admin Panel

- { - // Used to change the invite link - setLeagueName(val.target.value); - }} - value={leagueName} - /> -

- { - // Used to change the invite link - setStartingMoney(val.target.value); - }} - value={startingMoney} - /> -
- { - // Used to change the invite link - setTransfers(val.target.value); - }} - value={transfers} - /> -
- { - // Used to change the invite link - setDuplicatePlayers(val.target.value); - }} - value={duplicatePlayers} - /> -

- %, - }} - type="number" - onChange={(val) => { - // Used to change the invite link - setStarredPercentage(val.target.value); - }} - value={starredPercentage} - /> -

- e.admin == 1)} - renderTags={(value, getTagProps) => - value.map((option, index) => ( - - )) - } - onChange={(e, value) => { - let admins = value.map((e) => e.user); - setUsers((e2) => { - // Updates the value for all of the users - e2.forEach((e3) => { - e3.admin = admins.includes(parseInt(e3.user)); + if (admin) { + return ( + <> +

Admin Panel

+ { + // Used to change the invite link + setLeagueName(val.target.value); + }} + value={leagueName} + /> +

+ { + // Used to change the invite link + setStartingMoney(val.target.value); + }} + value={startingMoney} + /> +
+ { + // Used to change the invite link + setTransfers(val.target.value); + }} + value={transfers} + /> +
+ { + // Used to change the invite link + setDuplicatePlayers(val.target.value); + }} + value={duplicatePlayers} + /> +

+ %, + }} + type="number" + onChange={(val) => { + // Used to change the invite link + setStarredPercentage(val.target.value); + }} + value={starredPercentage} + /> +

+ e.admin == 1)} + renderTags={(value, getTagProps) => + value.map((option, index) => ( + + )) + } + onChange={(e, value) => { + let admins = value.map((e) => e.user); + setUsers((e2) => { + // Updates the value for all of the users + e2.forEach((e3) => { + e3.admin = admins.includes(parseInt(e3.user)); + }); + return [...e2]; }); - return [...e2]; - }); - }} - renderOption={(props, option) => ( - - - - )} - getOptionLabel={(option) => String(option.user)} - renderInput={(params) => ( - - )} - /> -

- - - ); + body: JSON.stringify({ + users, + settings: { + startingMoney: startingMoney * 1000000, + transfers, + duplicatePlayers, + starredPercentage, + leagueName, + }, + }), + }).then(async (res) => { + notify(await res.text(), res.ok ? "success" : "error"); + }); + }} + variant="contained" + > + Save Admin Settings + + + ); + } else { + return ( + <> +

Settings

+

Starting Money : {startingMoney}

+

Transfer Limit : {transfers}

+

Number of Squads a Player can be in : {duplicatePlayers}

+

Starred Player Percantage : {starredPercentage}%

+ + ); + } } // Used to show all the invites that exist and to delete an individual invite function Invite({ link, league, host, remove, notify }) { @@ -359,15 +371,14 @@ export default function Home({ > Add Invite - {admin && ( - - )} + ); }