Commit 51da2296 authored by Ermolaev Timur's avatar Ermolaev Timur

#157 пофиксил баги при создание нового проекта

parent 732adcdf
......@@ -49,7 +49,6 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
/**create new project */
router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {user, title,color}= req.body;
......@@ -86,6 +85,7 @@ router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
})
/**get project with all FK & tasks with all FK, by project ID */
router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
const project = await dataSource
.createQueryBuilder()
.select("project")
......
......@@ -27,8 +27,6 @@ const FullProject = ({ projectId }) => {
useEffect(() => {
if (projectId) {
dispatch(fetchProject(projectId))
} else {
dispatch(fetchProject(params.id))
}
dispatch(fetchUsers())
}, [params.id, dispatch, projectId]);
......
......@@ -32,8 +32,9 @@ const Projects = () => {
}, [])
const createNewProjectHandler = useCallback(() => {
dispatch(createProject({ title: projectTitle, user: user.id }, navigate))
}, [dispatch, projectTitle, user.id, navigate])
dispatch(createProject({ title: projectTitle, user: user.id }))
setModal(false)
}, [dispatch, projectTitle, user.id])
const deleteProjectHandler = useCallback((e, projectId) => {
e.stopPropagation();
......@@ -49,7 +50,7 @@ const Projects = () => {
}, [])
console.log(currentProject)
return <>
<Grid container justifyContent='space-between'>
......@@ -62,7 +63,7 @@ const Projects = () => {
/>
<Grid item xs={7} >
{currentProject ? <FullProject projectId={currentProject?.id} /> : null}
{currentProject ? <FullProject projectId={currentProject?.id ? currentProject?.id : null} /> : null}
</Grid>
</Grid>
......
......@@ -96,12 +96,12 @@ export const fetchProject = (id) => {
}
};
export const createProject = (projectData, navigate) => {
export const createProject = (projectData) => {
return async (dispatch) => {
try {
const response = await axios.post("/projects", projectData);
await axios.post("/projects", projectData);
dispatch(createProjectSuccess());
navigate("/projects/" + response.data.project.id)
dispatch(fetchProjects())
dispatch(showNotification("Проект успешно создан"))
} catch (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