Commit 29bd3775 authored by Ermolaev Timur's avatar Ermolaev Timur

#149 Реализовал создание задачи

parent e098bb78
...@@ -5,7 +5,7 @@ import CustomSelect from "../../../UI/СustomSelect/СustomSelect" ...@@ -5,7 +5,7 @@ import CustomSelect from "../../../UI/СustomSelect/СustomSelect"
import MaterialUIPickers from "./DateTimePicker/DateTimePicker"; import MaterialUIPickers from "./DateTimePicker/DateTimePicker";
import { Save } from "@mui/icons-material"; import { Save } from "@mui/icons-material";
function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange }) { function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler }) {
const workers = useMemo(()=>{ const workers = useMemo(()=>{
if (newTask?.project) { if (newTask?.project) {
return newTask?.project?.members.map((member)=>{return {value: member.user, text: member.user.displayName}}) return newTask?.project?.members.map((member)=>{return {value: member.user, text: member.user.displayName}})
...@@ -91,7 +91,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr ...@@ -91,7 +91,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr
/> />
</Grid> </Grid>
<Grid item xs={0.5} > <Grid item xs={0.5} >
<IconButton disabled={!newTask.title}> <IconButton disabled={!newTask.title} onClick={createNewTaskHandler}>
<Save /> <Save />
</IconButton> </IconButton>
</Grid> </Grid>
......
...@@ -5,7 +5,7 @@ import UsersTasksTableBody from "./UsersTasksTableBody/UsersTasksTableBody"; ...@@ -5,7 +5,7 @@ import UsersTasksTableBody from "./UsersTasksTableBody/UsersTasksTableBody";
import UsersTasksTableHead from "./UsersTasksTableHead/UsersTasksTableHead"; import UsersTasksTableHead from "./UsersTasksTableHead/UsersTasksTableHead";
function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, page, rowsPerPage, addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange}) { function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, page, rowsPerPage, addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler}) {
return ( return (
<TableContainer> <TableContainer>
<NewTaskForm <NewTaskForm
...@@ -14,6 +14,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag ...@@ -14,6 +14,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag
newTask={newTask} newTask={newTask}
allUserProjectsForModalTask={allUserProjectsForModalTask} allUserProjectsForModalTask={allUserProjectsForModalTask}
onDateChange={onDateChange} onDateChange={onDateChange}
createNewTaskHandler={()=>{createNewTaskHandler()}}
/> />
<Table <Table
sx={{ minWidth: 750 }} sx={{ minWidth: 750 }}
......
...@@ -2,7 +2,7 @@ import Paper from '@mui/material/Paper'; ...@@ -2,7 +2,7 @@ import Paper from '@mui/material/Paper';
import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar'; import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar';
import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination'; import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination';
import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer'; import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer';
import { fetchAllTasksByMembership } from '../../store/actions/tasksActions'; import { addTaskToUserTasksTable, fetchAllTasksByMembership } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { fetchAllUserProjects } from '../../store/actions/projectsActions'; import { fetchAllUserProjects } from '../../store/actions/projectsActions';
...@@ -18,10 +18,10 @@ export default function EnhancedTable() { ...@@ -18,10 +18,10 @@ export default function EnhancedTable() {
const [newTask, setNewTask] = useState({ const [newTask, setNewTask] = useState({
priority: '', priority: '',
title: '', title: '',
project: '', project: null,
description: '', description: '',
executor: '', executor: null,
dateTimeDeadLine: '', dateTimeDeadLine: null,
}) })
const [order, setOrder] = useState('asc'); const [order, setOrder] = useState('asc');
const [orderBy, setOrderBy] = useState('createdAt'); const [orderBy, setOrderBy] = useState('createdAt');
...@@ -34,10 +34,6 @@ export default function EnhancedTable() { ...@@ -34,10 +34,6 @@ export default function EnhancedTable() {
dispatch(fetchAllUserProjects()) dispatch(fetchAllUserProjects())
}, [dispatch]); }, [dispatch]);
useEffect(() => {
dispatch(fetchAllUserProjects())
}, [dispatch])
const onChangeNewTaskHandler = (e) => { const onChangeNewTaskHandler = (e) => {
const { value, name } = e.target; const { value, name } = e.target;
setNewTask((prevState => { setNewTask((prevState => {
...@@ -74,6 +70,34 @@ export default function EnhancedTable() { ...@@ -74,6 +70,34 @@ export default function EnhancedTable() {
}; };
const createTaskFromButtonHandler = () => { const createTaskFromButtonHandler = () => {
if (addFormStatus) {
setNewTask({
priority: '',
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: '',
})
}
setAddFormStatus((prevState) => { return !prevState })
}
const createNewTaskHandler = () => {
if (newTask.priority === '') {
const task = {...newTask, priority: null}
dispatch(addTaskToUserTasksTable(task))
} else {
dispatch(addTaskToUserTasksTable(newTask))
}
setNewTask({
priority: '',
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: '',
})
setAddFormStatus((prevState) => { return !prevState }) setAddFormStatus((prevState) => { return !prevState })
} }
...@@ -95,6 +119,7 @@ export default function EnhancedTable() { ...@@ -95,6 +119,7 @@ export default function EnhancedTable() {
newTask={newTask} newTask={newTask}
allUserProjectsForModalTask={allUserProjectsForModalTask} allUserProjectsForModalTask={allUserProjectsForModalTask}
onDateChange={onDateChange} onDateChange={onDateChange}
createNewTaskHandler={createNewTaskHandler}
/> />
<UsersTasksTablePagination <UsersTasksTablePagination
count={tasks.length} count={tasks.length}
......
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