diff --git a/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/ProjectCreationDialog.jsx b/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/ProjectCreationDialog.jsx new file mode 100644 index 0000000..3ef4573 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/ProjectCreationDialog.jsx @@ -0,0 +1,61 @@ +import { + Alert, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + TextField +} from "@mui/material"; +import {putRequest} from "@/common/utils/RequestUtil.js"; +import {useContext, useEffect, useState} from "react"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {DriveFileRenameOutline} from "@mui/icons-material"; + +export const ProjectCreationDialog = ({open, onClose}) => { + + const {updateProjects} = useContext(ProjectContext); + + const [name, setName] = useState(""); + const [creationError, setCreationError] = useState(null); + + const createProject = () => { + if (name.length === 0) return setCreationError("Name cannot be empty."); + + putRequest("/project", {name}).then(() => { + updateProjects(); + onClose(); + }).catch((e) => { + setCreationError(e.message); + }); + } + + const onKeyUp = (e) => { + if (e.key === "Enter") createProject(); + } + + useEffect(() => { + setName(""); + }, [open]); + + useEffect(() => { + setCreationError(null); + }, [name]); + + return ( + + Create a new project + + {creationError && {creationError}} + setName(e.target.value)} + placeholder="Name" + InputProps={{startAdornment: }} + onKeyUp={onKeyUp} sx={{mt: 1}} /> + + + + + + + ) +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/index.js b/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/index.js new file mode 100644 index 0000000..e59ba76 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Home/components/ProjectCreationDialog/index.js @@ -0,0 +1 @@ +export {ProjectCreationDialog as default} from "./ProjectCreationDialog.jsx"; \ No newline at end of file