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

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

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