diff --git a/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/PermissionCreationDialog.jsx b/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/PermissionCreationDialog.jsx new file mode 100644 index 0000000..b091730 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/PermissionCreationDialog.jsx @@ -0,0 +1,70 @@ +import {Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField} from "@mui/material"; +import {putRequest} from "@/common/utils/RequestUtil.js"; +import {useContext, useState} from "react"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Shield, Description} from "@mui/icons-material"; + +export const PermissionCreationDialog = ({open, onClose, fetchPermissions}) => { + const {currentProject} = useContext(ProjectContext); + + const [permission, setPermission] = useState(""); + const [description, setDescription] = useState(""); + + const [creationError, setCreationError] = useState(""); + + const updatePermission = async (event) => { + setCreationError(""); + setPermission(event.target.value); + } + + const updateDescription = async (event) => { + setCreationError(""); + setDescription(event.target.value); + } + + const closeDialog = () => { + onClose(); + + setPermission(""); + setDescription(""); + setCreationError(""); + } + + const createPermission = async () => { + try { + await putRequest(`/permission/${currentProject.id}`, {permission, description}); + fetchPermissions(); + + closeDialog(); + } catch (e) { + setCreationError(e.message); + } + } + + const onKeyUp = (event) => { + if (event.key === "Enter") createPermission(); + } + + return ( + + Create permission + + + {creationError && {creationError}} + + }}/> + + }}/> + + + + + + + ) +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/index.js b/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/index.js new file mode 100644 index 0000000..67eeaac --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Permissions/components/PermissionCreationDialog/index.js @@ -0,0 +1 @@ +export {PermissionCreationDialog as default} from "./PermissionCreationDialog"; \ No newline at end of file