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

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