наметила функцию добавления задачи

parent 80837de7
......@@ -20,59 +20,69 @@ import moment from "moment";
import CustomTableCell from "../../components/MyTasksCompoments/CustomTableCell";
import MaterialUIPickers from "../../components/MyTasksCompoments/DateTimePicker/DateTimePicker";
import BasicSelect from "../../components/UI/Select/Select";
import { fetchAllTasks, deleteTask,editTask,addTask } from "../../store/actions/tasksActions";
import { addTask } from "../../store/actions/tasksActions";
export default function NewTaskForm (props) {
// const onToggleEditModeDone = (id) => {
// const newTasks = recievedTasks.map((task) => {
// if (task.id === id) {
// return {
// ...task,
// isEditMode: false,
// readOnly: true,
// };
// }
// return task;
// });
// setRecievedTasks(newTasks);
// };
const task={
id:0,
title: "",
description: "",
createdAt: "",
dateTimeStart: null,
dateTimeDue: null,
accomplish: "",
priority: "",
author: {
name: "",
},
executors: [
{ name: "" }
],
isEditMode:false,
readOnly: true
};
const dispatch = useDispatch();
const user = useSelector((state) => state.users.user);
const current = new Date();
const date = `${current.getDate()}/${current.getMonth()+1}/${current.getFullYear()}`;
const onToggleEditMode = (id) => {
console.log(task)
const [task, setTask] =useState(
{
id:0,
title: "",
description: "",
createdAt: date,
dateTimeStart: null,
dateTimeDue: null,
accomplish: "",
priority: "",
author: user,
executors: [
{ name: "" }
],
isEditMode:false,
readOnly: true
}
);
const onToggleEditMode = (id) => {
const newTask = ((task) => {
if (task.id === id) {
return {
...task,
isEditMode: true,
readOnly: false,
};
}
return task;
});
setTask(newTask);
};
console.log(task)
const onToggleEditModeDone = (id) => {
const newTasks = (task) => {
if (task.id === id) {
return {
...task,
isEditMode: false,
readOnly: true,
};
}
return task;
};
setTask(newTasks);
};
const HandleAddTask=()=>{
console.log(task)
dispatch(addTask(task))
}
return (
<TableRow hover key={task.id}>
<TableCell
......@@ -167,7 +177,7 @@ export default function NewTaskForm (props) {
{task.isEditMode ? (
<IconButton
aria-label="done"
onClick={() => {props.onToggleEditModeDone(task.id); props.HandleEditTask(task) }}
onClick={() => {onToggleEditModeDone(task.id); HandleAddTask(task) }}
>
<Done />
</IconButton>
......@@ -181,7 +191,7 @@ export default function NewTaskForm (props) {
)}
</TableCell>
<TableCell>
<Tooltip title="Delete">
{/* <Tooltip title="Delete">
<IconButton
onClick={(id) => {
props.deleteHandle(task.id);
......@@ -189,7 +199,7 @@ export default function NewTaskForm (props) {
>
<DeleteIcon />
</IconButton>
</Tooltip>
</Tooltip> */}
</TableCell>
</TableRow>
);
......
......@@ -56,6 +56,7 @@ function stableSort(array, comparator) {
}
export default function EnhancedTable() {
const dispatch = useDispatch();
useEffect(() => {
......@@ -63,18 +64,21 @@ export default function EnhancedTable() {
}, [dispatch]);
const tasks = useSelector((state) => state.tasks.tasks);
console.log(tasks)
const [recievedTasks, setRecievedTasks] = useState([]);
const [order, setOrder] = useState("asc");
const [orderBy, setOrderBy] = useState("id");
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] =useState(5);
const [modal, setModal] = useState({
open: false,
task: null,
});
const projects=[
"project1",
"project2",
"project3"
]
const [order, setOrder] = React.useState("asc");
const [orderBy, setOrderBy] = React.useState("id");
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(5);
console.log(tasks)
const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === "asc";
......@@ -111,6 +115,7 @@ console.log(tasks)
const name = e.target.name;
const { id } = task;
const newTasks = recievedTasks.map((task) => {
console.log(task)
if (task.id === id) {
return { ...task, [name]: value };
}
......@@ -182,33 +187,11 @@ console.log(tasks)
dispatch(editTask(task))
}
const addTask = () => {
// let newTasks=[...tasks]
tasks.unshift({
title: "",
description: "",
priority: "",
author: "",
executor: "",
dateTimeStart: "",
dateTimeDue: "",
id: 4,
createdAt: "",
accomplish: " ",
});
// tasks=newTasks;
};
const deleteHandle = (id) => {
dispatch(deleteTask(id));
};
const [modal, setModal] = useState({
open: false,
task: null,
});
const onModalOpen = (event, task) => {
event.stopPropagation();
setModal({ ...modal, open: true, id: task.id });
......@@ -222,7 +205,7 @@ console.log(tasks)
const [projectName, setProjectName] = React.useState([]);
const [filter, setFilter] = React.useState(false);
const onClose=(projectName)=>{
console.log(projectName)
setFilter(true)
}
useEffect(() => {
......@@ -280,7 +263,7 @@ console.log(tasks)
</TableCell>
</TableRow> */}
{/* <NewTaskForm
<NewTaskForm
onChange={onChange}
onModalOpen={onModalOpen}
onAuthorChange={onAuthorChange}
......@@ -289,7 +272,7 @@ console.log(tasks)
onToggleEditModeDone={onToggleEditModeDone}
HandleEditTask={HandleEditTask}
deleteHandle={deleteHandle}
/> */}
/>
{stableSort(recievedTasks, getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
......
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