Commit 8a1dd26e authored by Ibadullina Inabat's avatar Ibadullina Inabat

#73 реализована модалка на добавление проекта

parent 5c2142fd
...@@ -51,14 +51,6 @@ const App = () => { ...@@ -51,14 +51,6 @@ const App = () => {
<FullProject/> <FullProject/>
</ProtectedRoute> </ProtectedRoute>
}/> }/>
<Route path={"/projects/add"} element={
<ProtectedRoute
isAllowed={user}
redirectUrl={"/sign-in"}
>
<NewProject/>
</ProtectedRoute>
}/>
<Route path={"/"} element={ <Route path={"/"} element={
<ProtectedRoute <ProtectedRoute
isAllowed={user} isAllowed={user}
......
import {Button, Grid} from "@mui/material"; import {Box, Button, Grid, Modal} from "@mui/material";
import {useState} from "react"; import {useState} from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import FormElement from "../UI/Form/FormElement/FormElement"; import FormElement from "../UI/Form/FormElement/FormElement";
import {Typography} from "@mui/material";
const style = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};
const ProjectForm = ({onSubmit}) => { const ProjectForm = ({onSubmit}) => {
const users = useSelector(state => state.users) const users = useSelector(state => state.users)
console.log(users) console.log(users)
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const [state, setState] = useState({ const [state, setState] = useState({
title: "", title: ""
color: ""
}); });
const submitFormHandler = (e) => { const submitFormHandler = (e) => {
e.preventDefault(); e.preventDefault();
let project = {title: state.title, color: state.color} let project = {title: state.title}
console.log(project); console.log(project);
onSubmit(project); onSubmit(project);
}; };
const inputChangeHandler = (e) => { const inputChangeHandler = (e) => {
...@@ -26,31 +42,44 @@ const ProjectForm = ({onSubmit}) => { ...@@ -26,31 +42,44 @@ const ProjectForm = ({onSubmit}) => {
}); });
}; };
return <form onSubmit={submitFormHandler}> return (
<div >
<Button onClick={handleOpen} >Add project</Button>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
onSubmit={submitFormHandler}
>
<Box sx={style}>
<form >
<Grid container direction="column" spacing={2}> <Grid container direction="column" spacing={2}>
<Typography variant="h4">New project</Typography>
<FormElement <FormElement
onChange={inputChangeHandler} onChange={inputChangeHandler}
name={"title"} name={"title"}
label={"Title"} label={"Title"}
state={state} state={state}
/>
<FormElement
onChange={inputChangeHandler}
name={"color"}
label={"Color"}
state={state}
/> />
<Grid item> <Grid item>
<Button <Button
type="submit" type="submit"
color="primary" color="primary"
variant="contained" variant="contained"
> >
Create Create
</Button> </Button>
</Grid> </Grid>
</Grid> </Grid>
</form> </form>
</Box>
</Modal>
</div>
);
}; };
export default ProjectForm; export default ProjectForm;
\ No newline at end of file
...@@ -34,7 +34,7 @@ const FullProject = () => { ...@@ -34,7 +34,7 @@ const FullProject = () => {
</strong> </strong>
<strong> <strong>
<br></br> <br></br>
Админ проекта: {project?.project?.members} {/* Админ проекта: {project?.project?.members} */}
</strong> </strong>
<strong> <strong>
<br></br> <br></br>
......
import {useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import {useDispatch, useSelector} from "react-redux"; import {useDispatch, useSelector} from "react-redux";
import {Typography} from "@mui/material";
import { useEffect } from "react"; import { useEffect } from "react";
import ProjectForm from "../../components/ProjectForm/ProjectForm"; import ProjectForm from "../../components/ProjectForm/ProjectForm";
import { createProject, fetchProjects } from "../../store/actions/projectsActions"; import { createProject, fetchProjects } from "../../store/actions/projectsActions";
...@@ -9,8 +9,12 @@ const NewProject = () => { ...@@ -9,8 +9,12 @@ const NewProject = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const projects = useSelector(state => state.projects.projects); const projects = useSelector(state => state.projects.projects);
const navigate = useNavigate(); const navigate = useNavigate();
let lastProject = projects.projects[projects.projects.length - 1];
const onSubmit = async (projectData) => { const onSubmit = async (projectData) => {
await dispatch(createProject(projectData, navigate)); await dispatch(createProject(projectData, navigate));
console.log(projectData)
console.log(lastProject)
}; };
useEffect(()=> { useEffect(()=> {
...@@ -19,7 +23,6 @@ const NewProject = () => { ...@@ -19,7 +23,6 @@ const NewProject = () => {
return ( return (
<> <>
<Typography variant="h2">New project</Typography>
<ProjectForm projects={projects} onSubmit={onSubmit} /> <ProjectForm projects={projects} onSubmit={onSubmit} />
</> </>
); );
......
...@@ -6,6 +6,7 @@ import Loader from "../../components/UI/Loader/Loader"; ...@@ -6,6 +6,7 @@ import Loader from "../../components/UI/Loader/Loader";
import HasAccess from "../../components/UI/HasAccess/HasAccess"; import HasAccess from "../../components/UI/HasAccess/HasAccess";
import { fetchProjects } from "../../store/actions/projectsActions"; import { fetchProjects } from "../../store/actions/projectsActions";
import ProjectsList from "../../components/ProjectsList/ProjectsList"; import ProjectsList from "../../components/ProjectsList/ProjectsList";
import NewProject from "../NewProject/NewProject";
const Projects = () => { const Projects = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
...@@ -34,9 +35,7 @@ const Projects = () => { ...@@ -34,9 +35,7 @@ const Projects = () => {
</Grid> </Grid>
<HasAccess roles={["superuser", "admin", "user"]} > <HasAccess roles={["superuser", "admin", "user"]} >
<Grid item> <Grid item>
<Button component={Link} to="/projects/add"> <NewProject/>
Add project
</Button>
</Grid> </Grid>
</HasAccess> </HasAccess>
</Grid> </Grid>
......
...@@ -46,9 +46,10 @@ export const fetchProject = (id) => { ...@@ -46,9 +46,10 @@ export const fetchProject = (id) => {
export const createProject = (projectData, navigate) => { export const createProject = (projectData, navigate) => {
return async (dispatch) => { return async (dispatch) => {
try { try {
await axios.post("/projects", projectData); const response = await axios.post("/projects", projectData);
dispatch(createProjectSuccess()); dispatch(createProjectSuccess());
navigate("/"); console.log(response.data)
navigate("/projects/" + response.data.project.id)
dispatch(showNotification("Проект успешно создан")) dispatch(showNotification("Проект успешно создан"))
} catch (e) { } catch (e) {
console.log(e); console.log(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment