diff --git a/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/KeyCreationDialog.jsx b/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/KeyCreationDialog.jsx new file mode 100644 index 0000000..5ca5a33 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/KeyCreationDialog.jsx @@ -0,0 +1,87 @@ +import { + Alert, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, FormControl, + InputLabel, MenuItem, OutlinedInput, + Select, + TextField +} from "@mui/material"; +import {putRequest} from "@/common/utils/RequestUtil.js"; +import {useContext, useState} from "react"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Key} from "@mui/icons-material"; + +export const KeyCreationDialog = ({open, onClose, fetchKeys, setCreatedKey}) => { + const {currentProject} = useContext(ProjectContext); + + const [name, setName] = useState(""); + const [role, setRole] = useState(0); + + const [creationError, setCreationError] = useState(""); + + const updateName = async (event) => { + setCreationError(""); + setName(event.target.value); + } + + const updateDescription = async (event) => { + setCreationError(""); + setRole(event.target.value); + } + + const closeDialog = () => { + onClose(); + + setName(""); + setRole(0); + setCreationError(""); + } + + const createKey = async () => { + try { + const {token} = await putRequest(`/key/${currentProject.id}`, {name, role}); + setCreatedKey(token); + fetchKeys(); + + closeDialog(); + } catch (e) { + setCreationError(e.message); + } + } + + const onKeyUp = (event) => { + if (event.key === "Enter") createKey(); + } + + return ( + + Create access key + + + {creationError && {creationError}} + + }}/> + + + Role + + + + + + + + + ) +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/index.js b/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/index.js new file mode 100644 index 0000000..ad36a5e --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/AccessKeys/components/KeyCreationDialog/index.js @@ -0,0 +1 @@ +export {KeyCreationDialog as default} from "./KeyCreationDialog.jsx"; \ No newline at end of file