diff --git a/code/frontend/src/PageSwitcher.js b/code/frontend/src/PageSwitcher.js index bb070b0..bde5261 100644 --- a/code/frontend/src/PageSwitcher.js +++ b/code/frontend/src/PageSwitcher.js @@ -8,16 +8,20 @@ import PageSandbox from "./routes/PageSandbox" import PageDashboard from "./routes/PageDashboard" import PageRoot from "./routes/PageRoot" import PageEdit from "./routes/PageEdit" +import PageUsers from "./routes/PageUsers" export default function PageSwitcher({ ...props }) { return ( + + + - - + + diff --git a/code/frontend/src/components/interactive/BoxUserCreate.js b/code/frontend/src/components/interactive/BoxUserCreate.js new file mode 100644 index 0000000..0d5fc8a --- /dev/null +++ b/code/frontend/src/components/interactive/BoxUserCreate.js @@ -0,0 +1,74 @@ +import React, { useContext, useMemo, useState } from "react" +import FormLabelled from "../base/FormLabelled" +import FormLabel from "../base/formparts/FormLabel" +import InputWithIcon from "../base/InputWithIcon" +import { faEnvelope, faKey, faPlus, faUser } from "@fortawesome/free-solid-svg-icons" +import FormButton from "../base/formparts/FormButton" +import BoxFull from "../base/BoxFull" +import useBackend from "../../hooks/useBackend" +import ContextUser from "../../contexts/ContextUser" +import FormAlert from "../base/formparts/FormAlert" + + +export default function BoxUserCreate({ children, ...props }) { + const { fetchDataAuth } = useContext(ContextUser) + const [username, setUsername] = useState("") + const [email, setEmail] = useState("") + const [password, setPassword] = useState("") + + const body = useMemo( + () => { + return { + "email": email, + "username": username, + "password": password, + } + }, + [email, username, password], + ) + const { error, fetchNow: createNow } = useBackend(fetchDataAuth, "POST", "/api/v1/users/", body) + + return ( + + + + setUsername(event.target.value)} + /> + + + setEmail(event.target.value)} + /> + + + setPassword(event.target.value)} + /> + + {error ? + + {error.toString()} + + : null} + createNow()} + > + Create + + + {children} + + ) +} diff --git a/code/frontend/src/components/interactive/Sidebar.js b/code/frontend/src/components/interactive/Sidebar.js index 31ab185..a527e02 100644 --- a/code/frontend/src/components/interactive/Sidebar.js +++ b/code/frontend/src/components/interactive/Sidebar.js @@ -1,9 +1,17 @@ -import React, { Fragment, useContext } from "react" +import React, { useContext } from "react" import Style from "./Sidebar.module.css" import classNames from "classnames" import Logo from "../interactive/Logo" import ButtonSidebar from "../base/ButtonSidebar" -import { faCog, faExclamationTriangle, faFolder, faHome, faKey, faWrench } from "@fortawesome/free-solid-svg-icons" +import { + faCog, + faExclamationTriangle, + faFolder, + faHome, + faKey, + faUser, + faWrench, +} from "@fortawesome/free-solid-svg-icons" import ContextUser from "../../contexts/ContextUser" @@ -24,16 +32,24 @@ export default function Sidebar({ className, ...props }) { { user ? - + <> Dashboard Repositories Alerts Settings - + : - + <> Login - + + } + { + user.isAdmin ? + <> + Users + + : + null } { process.env.NODE_ENV === "development" ? diff --git a/code/frontend/src/routes/PageUsers.js b/code/frontend/src/routes/PageUsers.js index d70f7b3..4dc66bf 100644 --- a/code/frontend/src/routes/PageUsers.js +++ b/code/frontend/src/routes/PageUsers.js @@ -1,15 +1,29 @@ -import React from "react" +import React, { useContext } from "react" import Style from "./PageDashboard.module.css" import classNames from "classnames" import BoxHeader from "../components/base/BoxHeader" +import BoxUserCreate from "../components/interactive/BoxUserCreate" +import ContextUser from "../contexts/ContextUser" +import BoxAlert from "../components/base/BoxAlert" -export default function PageDashboard({ children, className, ...props }) { +export default function PageUsers({ children, className, ...props }) { + const { user } = useContext(ContextUser) + + if(!user.isAdmin) { + return ( + + Non sei un amministratore, pertanto non puoi gestire gli utenti della piattaforma. + + ) + } + return (
- Manage users + Gestisci utenti +
) } diff --git a/code/frontend/src/routes/PageUsers.module.css b/code/frontend/src/routes/PageUsers.module.css index 4d65253..83b0a1a 100644 --- a/code/frontend/src/routes/PageUsers.module.css +++ b/code/frontend/src/routes/PageUsers.module.css @@ -18,6 +18,14 @@ grid-area: a; } -.RepositoryEditor { +.CreateUser { grid-area: b; } + +.DeleteUser { + grid-area: c; +} + +.UserList { + grid-area: d; +} \ No newline at end of file