Merge branch 'task-136-fix/project_select_my_tasks' into 'development'

Task 136 fix/project select my tasks

See merge request !112
parents b73a244c 9530748a
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"class-validator": "^0.13.2", "class-validator": "^0.13.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.18.2", "express": "^4.18.2",
"express-async-errors": "^3.1.1",
"mongoose": "^6.7.0", "mongoose": "^6.7.0",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4", "nanoid": "^3.3.4",
...@@ -3329,6 +3330,14 @@ ...@@ -3329,6 +3330,14 @@
"node": ">= 0.10.0" "node": ">= 0.10.0"
} }
}, },
"node_modules/express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==",
"peerDependencies": {
"express": "^4.16.2"
}
},
"node_modules/express/node_modules/debug": { "node_modules/express/node_modules/debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
...@@ -8887,6 +8896,12 @@ ...@@ -8887,6 +8896,12 @@
} }
} }
}, },
"express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==",
"requires": {}
},
"fast-deep-equal": { "fast-deep-equal": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
"class-validator": "^0.13.2", "class-validator": "^0.13.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.18.2", "express": "^4.18.2",
"express-async-errors": "^3.1.1",
"mongoose": "^6.7.0", "mongoose": "^6.7.0",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4", "nanoid": "^3.3.4",
......
...@@ -6,6 +6,7 @@ import { priorityType, Task, taskFinishType } from "./models/Task"; ...@@ -6,6 +6,7 @@ import { priorityType, Task, taskFinishType } from "./models/Task";
import { Project } from "./models/Project"; import { Project } from "./models/Project";
import { Member, MemberRole } from "./models/Member"; import { Member, MemberRole } from "./models/Member";
import { DateTimeTask } from "./models/DateTimeTask"; import { DateTimeTask } from "./models/DateTimeTask";
import { PasswordRecovery } from "./models/PasswordRecovery";
function randomIntFromInterval(min:number, max:number) { function randomIntFromInterval(min:number, max:number) {
min = Math.ceil(min); min = Math.ceil(min);
...@@ -50,6 +51,8 @@ const loadFixtures = async () => { ...@@ -50,6 +51,8 @@ const loadFixtures = async () => {
await repositoryProject.delete({}) await repositoryProject.delete({})
const repositoryUser = myDataSource.getRepository(User); const repositoryUser = myDataSource.getRepository(User);
await repositoryUser.delete({}); await repositoryUser.delete({});
const repositoryPasswordRecovery = myDataSource.getRepository(PasswordRecovery);
await repositoryPasswordRecovery.delete({});
console.log('========================== ' + '\n' + 'Data Source has been cleared!' +'\n' + '==========================') console.log('========================== ' + '\n' + 'Data Source has been cleared!' +'\n' + '==========================')
const userRoles = [{role: UserRole.SUPERUSER}, {role: UserRole.USER}, {role: UserRole.USER},{role: UserRole.USER},]; const userRoles = [{role: UserRole.SUPERUSER}, {role: UserRole.USER}, {role: UserRole.USER},{role: UserRole.USER},];
...@@ -68,6 +71,26 @@ const loadFixtures = async () => { ...@@ -68,6 +71,26 @@ const loadFixtures = async () => {
user.role = userRoles[i].role; user.role = userRoles[i].role;
user.generateToken() user.generateToken()
await user.save(); await user.save();
// начало: создание проектов "Личные дела" и "Не определелено" новому юзеру
const newProject = new Project();
newProject.title = 'Личные дела';
newProject.color= '#f595ee';
await newProject.save()
const newMember = new Member();
newMember.user = user;
newMember.project = newProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
const notDefinedTaskProject = new Project();
notDefinedTaskProject.title = 'Не определено';
notDefinedTaskProject.color= '#03fcfc';
await notDefinedTaskProject.save()
const notDefinedTaskProjectMember = new Member();
notDefinedTaskProjectMember.user = user;
notDefinedTaskProjectMember.project = notDefinedTaskProject;
notDefinedTaskProjectMember.roleProject = MemberRole.ADMIN;
await notDefinedTaskProjectMember.save();
// конец
users.push(user) users.push(user)
} }
...@@ -77,11 +100,13 @@ const loadFixtures = async () => { ...@@ -77,11 +100,13 @@ const loadFixtures = async () => {
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
let dateOfMonth = randomIntFromInterval(20, 30) let currentTime = new Date()
let startdateOfMonth = randomIntFromInterval(20, 24)
let enddateOfMonth = randomIntFromInterval(25, 29)
let deadLineDateOfMonth = randomIntFromInterval(1, 10) let deadLineDateOfMonth = randomIntFromInterval(1, 10)
let startDateTime = new Date(2022, 10, dateOfMonth, randomIntFromInterval(16, 21), 0, 0); let startDateTime = new Date(currentTime.getFullYear(), currentTime.getMonth()+1,startdateOfMonth , randomIntFromInterval(11, 18), 0, 0);
let dueDateTime = new Date(2022, 10, dateOfMonth, randomIntFromInterval(22, 22), 0, 0); let dueDateTime = new Date(currentTime.getFullYear(), currentTime.getMonth()+1,startdateOfMonth, randomIntFromInterval(19, 20), 0, 0);
let deadLine = new Date(2022, 11, deadLineDateOfMonth, 0, 0, 0); let deadLine = new Date(currentTime.getFullYear(), currentTime.getMonth()+2, enddateOfMonth, randomIntFromInterval(20, 22), 0, 0);
const newDateTimeTask= new DateTimeTask() const newDateTimeTask= new DateTimeTask()
newDateTimeTask.dateTimeStart=startDateTime; newDateTimeTask.dateTimeStart=startDateTime;
newDateTimeTask.dateTimeDue=dueDateTime; newDateTimeTask.dateTimeDue=dueDateTime;
......
import 'express-async-errors';
import express, { NextFunction, Request, Response, Router } from "express"; import express, { NextFunction, Request, Response, Router } from "express";
import { myDataSource } from "./app-data-source"; import { myDataSource } from "./app-data-source";
import { Task } from "./models/Task"; import { Task } from "./models/Task";
...@@ -59,7 +60,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next ...@@ -59,7 +60,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
} }
const {executorStatus, authorStatus} = req.body const {executorStatus, authorStatus} = req.body
if (!executorStatus && !authorStatus) { if (!executorStatus && !authorStatus) {
res.status(403).send({message:'user is not authorized'}) return res.status(403).send({message:'user is not authorized'})
} }
req.body={...req.body, task:task} req.body={...req.body, task:task}
next() next()
......
...@@ -49,8 +49,26 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> { ...@@ -49,8 +49,26 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
/**create new project */ /**create new project */
router.post('/',auth, async (req:Request, res:Response): Promise<Response> => { router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'}) if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {user, title,color}= req.body; const {user, title,color}= req.body;
try{
const projectCheck = await dataSource
.getRepository(Project)
.find({
where:{
title:title
}
})
if(projectCheck.length>0) {return res.status(400).send({message:"suchc Project already exists"})}
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
try{
const member:Member = new Member; const member:Member = new Member;
member.user= user; member.user= user;
member.roleProject= MemberRole.ADMIN; member.roleProject= MemberRole.ADMIN;
...@@ -61,6 +79,10 @@ router.post('/',auth, async (req:Request, res:Response): Promise<Response> => { ...@@ -61,6 +79,10 @@ router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
project.members=[member] project.members=[member]
await project.save() await project.save()
return res.send({project}) return res.send({project})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
}) })
/**get project with all FK & tasks with all FK, by project ID */ /**get project with all FK & tasks with all FK, by project ID */
router.get("/:id",async (req:Request, res:Response): Promise<Response> => { router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
......
import 'express-async-errors';
import express,{Router, Request, Response } from 'express'; import express,{Router, Request, Response } from 'express';
import {Task} from '../models/Task'; import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source'; import {myDataSource} from '../app-data-source';
...@@ -27,6 +28,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => { ...@@ -27,6 +28,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task for table MyTask*/ /**create new task for table MyTask*/
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority} = req.body; const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority} = req.body;
console.log('dateTimeStart \n', dateTimeStart, "dateTimeDue\n", dateTimeDue, 'dateTimeDeadLine\n ', dateTimeDeadLine)
let dateTimeDueFinal = dateTimeDue let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart let dateTimeStartFinal = dateTimeStart
let dateTimeDeadlineFinal= dateTimeDeadLine let dateTimeDeadlineFinal= dateTimeDeadLine
...@@ -34,7 +36,6 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -34,7 +36,6 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
dateTimeDueFinal = dateTimeDeadLine dateTimeDueFinal = dateTimeDeadLine
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1) dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
} }
console.log('datTeimeDeadLine ', dateTimeDeadLine)
const newTask = new Task(); const newTask = new Task();
newTask.title = title; newTask.title = title;
...@@ -112,6 +113,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=> ...@@ -112,6 +113,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
const newTask = new Task(); const newTask = new Task();
newTask.title = title; newTask.title = title;
newTask.description = description; newTask.description = description;
const currentTime = new Date();
if (project) { if (project) {
const watcherOfProject = await dataSource const watcherOfProject = await dataSource
.getRepository(Project) .getRepository(Project)
...@@ -196,14 +198,15 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -196,14 +198,15 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
/**check tasks of current user where he is executor(works for tbl MyTasks), search by id*/ /**check tasks of current user where he is executor(works for tbl MyTasks), search by id*/
router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
let projectsRawId =[]
try{
const user = req.body.user const user = req.body.user
const projectsRawId = await dataSource projectsRawId = await dataSource
.getRepository(Project) .getRepository(Project)
.find({ .find({
select:{ select:{
id:true id:true
}, },
where:{ where:{
title:Not(Equal("Не определено")), title:Not(Equal("Не определено")),
members:{ members:{
...@@ -246,6 +249,9 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ ...@@ -246,6 +249,9 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
} }
}) })
return res.send({tasks, projects}) return res.send({tasks, projects})
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
}) })
...@@ -386,6 +392,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{ ...@@ -386,6 +392,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
/**check other users tasks that are related to the user through common projects, by user token*/ /**check other users tasks that are related to the user through common projects, by user token*/
router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{
const {user} = req.body const {user} = req.body
try{
const projectsWithTasks = await dataSource const projectsWithTasks = await dataSource
.getRepository(Project) .getRepository(Project)
.find( .find(
...@@ -407,6 +414,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -407,6 +414,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
} }
} }
}}) }})
if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'}) if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'})
let tasks:Task[] = [] let tasks:Task[] = []
if (projectsWithTasks.length>0) { if (projectsWithTasks.length>0) {
...@@ -416,6 +424,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -416,6 +424,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
} }
} }
} }
const projectIds= projectsWithTasks.map(project=> {return project.id}) const projectIds= projectsWithTasks.map(project=> {return project.id})
const projects = await dataSource const projects = await dataSource
.getRepository(Project) .getRepository(Project)
...@@ -430,9 +439,12 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -430,9 +439,12 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
roleProject: Not(MemberRole.WATCHER) roleProject: Not(MemberRole.WATCHER)
} }
}, },
}) })
return res.send({projects, tasks}) return res.send({projects, tasks})
} catch(e){
console.log('Error: ',(e as Error).message);
return res.status(502).send({message:(e as Error).message})
}
}) })
......
...@@ -93,15 +93,26 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response): ...@@ -93,15 +93,26 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
user.role = role; user.role = role;
user.generateToken(); user.generateToken();
await user.save(); await user.save();
/**Создание проектов "Личные дела" и "Не определено"
* у только что созданого пользователя*/
const newProject = new Project(); const newProject = new Project();
newProject.title = 'Личные дела'; newProject.title = 'Личные дела';
newProject.color= 'Green'; newProject.color= '#f595ee';
await newProject.save() await newProject.save()
const newMember = new Member(); const newMember = new Member();
newMember.user = user; newMember.user = user;
newMember.project = newProject; newMember.project = newProject;
newMember.roleProject = MemberRole.ADMIN; newMember.roleProject = MemberRole.ADMIN;
await newMember.save(); await newMember.save();
const notDefinedTaskProject = new Project();
notDefinedTaskProject.title = 'Не определено';
notDefinedTaskProject.color= '#03fcfc';
await notDefinedTaskProject.save()
const notDefinedTaskProjectMember = new Member();
notDefinedTaskProjectMember.user = user;
notDefinedTaskProjectMember.project = notDefinedTaskProject;
notDefinedTaskProjectMember.roleProject = MemberRole.ADMIN;
await notDefinedTaskProjectMember.save();
const userToFront:User|null = await dataSource.manager.findOneBy(User, { const userToFront:User|null = await dataSource.manager.findOneBy(User, {
email: user.email email: user.email
......
...@@ -13,14 +13,17 @@ import { ...@@ -13,14 +13,17 @@ import {
} from "@mui/material"; } from "@mui/material";
import { useState } from "react"; import { useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { AddBox, Luggage } from "@mui/icons-material"; import { AddBox
// , Luggage
} from "@mui/icons-material";
import moment from "moment"; import moment from "moment";
import CustomTableCell from "./CustomTableCell"; import CustomTableCell from "./CustomTableCell";
import MaterialUIPickers from "./DateTimePicker/DateTimePicker"; import MaterialUIPickers from "./DateTimePicker/DateTimePicker";
import BasicSelect from "../UI/Select/Select"; import BasicSelect from "../UI/Select/Select";
import { addTask } from "../../store/actions/tasksActions"; import { addTask } from "../../store/actions/tasksActions";
import TaskModal from "./TaskModal/TaskModal"; import TaskModal from "./TaskModal/TaskModal";
import {dateToISOLikeButLocal} from '../../helpers/CalendarHelpers'; // import {dateToISOLikeButLocal} from '../../helpers/CalendarHelpers';
// import DateTimePicker from "../Calendars/UI/DateTimePicker/DateTimePicker";
export default function NewTaskForm({ projects, setAddTaskForm }) { export default function NewTaskForm({ projects, setAddTaskForm }) {
console.log('new task form') console.log('new task form')
...@@ -37,7 +40,7 @@ export default function NewTaskForm({ projects, setAddTaskForm }) { ...@@ -37,7 +40,7 @@ export default function NewTaskForm({ projects, setAddTaskForm }) {
dateTimeDeadLine: null, dateTimeDeadLine: null,
dateTimeTasks: [], dateTimeTasks: [],
dateTimeDue: null, dateTimeDue: null,
project: null, project: projects?projects.find(project=>project.title==="Личные дела"):null,
accomplish: "opened", accomplish: "opened",
priority: "B", priority: "B",
author: { id: user.id }, author: { id: user.id },
...@@ -53,6 +56,8 @@ export default function NewTaskForm({ projects, setAddTaskForm }) { ...@@ -53,6 +56,8 @@ export default function NewTaskForm({ projects, setAddTaskForm }) {
setModal(true); setModal(true);
}; };
console.log('task ', task)
const handleClose = () => { const handleClose = () => {
setModal(false); setModal(false);
}; };
......
...@@ -6,11 +6,6 @@ import FormControl from "@mui/material/FormControl"; ...@@ -6,11 +6,6 @@ import FormControl from "@mui/material/FormControl";
import Select from "@mui/material/Select"; import Select from "@mui/material/Select";
export default function BasicSelect({value,label,name,onChange,task,items}) { export default function BasicSelect({value,label,name,onChange,task,items}) {
// console.log('select value ', value)
// console.log('select label ', label)
// console.log('select name ', name)
// console.log('select task ', task)
// console.log('select items ', items)
return ( return (
<Box sx={{ minWidth: 60, m: 0}}> <Box sx={{ minWidth: 60, m: 0}}>
<FormControl fullWidth> <FormControl fullWidth>
...@@ -20,7 +15,6 @@ export default function BasicSelect({value,label,name,onChange,task,items}) { ...@@ -20,7 +15,6 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
id="demo-simple-select" id="demo-simple-select"
value={value} value={value}
defaultValue='' defaultValue=''
// displayEmpty={true}
label={label} label={label}
name={name} name={name}
onChange={(e) => onChange(e, task)} onChange={(e) => onChange(e, task)}
......
...@@ -40,7 +40,7 @@ export default function NewTaskForm({ ...@@ -40,7 +40,7 @@ export default function NewTaskForm({
dateTimeDeadLine: null, dateTimeDeadLine: null,
dateTimeTasks: [], dateTimeTasks: [],
dateTimeDue: null, dateTimeDue: null,
project: null, project: projects?projects.find(project=>project.title==="Не определено"):null,
accomplish: "opened", accomplish: "opened",
priority: "B", priority: "B",
author: { id: user.id }, author: { id: user.id },
...@@ -49,7 +49,6 @@ export default function NewTaskForm({ ...@@ -49,7 +49,6 @@ export default function NewTaskForm({
isEditMode: true, isEditMode: true,
}); });
const [modal, setModal] = useState(false); const [modal, setModal] = useState(false);
console.log('NewTaskForm currentProject ', currentProject )
const onModalOpen = (event, task) => { const onModalOpen = (event, task) => {
event.stopPropagation(); event.stopPropagation();
...@@ -178,7 +177,7 @@ export default function NewTaskForm({ ...@@ -178,7 +177,7 @@ export default function NewTaskForm({
task={task} task={task}
onChange={onExecutorChange} onChange={onExecutorChange}
name="executor" name="executor"
value={task.executor?.id} value={task?.executor?.id}
defaultValue={user.id} defaultValue={user.id}
/> />
</TableCell> </TableCell>
......
import * as React from "react"; import React,{useState} from "react";
import { import {
TableCell, TableCell,
TableRow, TableRow,
...@@ -33,17 +33,20 @@ const TableRowTask= ({ ...@@ -33,17 +33,20 @@ const TableRowTask= ({
deleteDateTimeTask, deleteDateTimeTask,
onChange, onChange,
onModalOpen, onModalOpen,
onProjectChange, // onProjectChange,
onExecutorChange, // onExecutorChange,
uniqueProjects, uniqueProjects,
executors, // executors,
onAuthorChange,
onDateChange, onDateChange,
onToggleEditMode, onToggleEditMode,
onToggleEditModeDone, onToggleEditModeDone,
})=>{ })=>{
const [open, setOpen] = React.useState(false); const [open, setOpen] = useState(false);
const [defaultExecutor, setDefaultExecutor] = useState(task.executor?.id)
const [executors, setExecutors]=useState([])
const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]);
const roudHourUp =(dateIso)=>{ const roudHourUp =(dateIso)=>{
let m = moment(dateIso); let m = moment(dateIso);
...@@ -61,6 +64,64 @@ const TableRowTask= ({ ...@@ -61,6 +64,64 @@ const TableRowTask= ({
return weekDays[date.day()]; return weekDays[date.day()];
} }
const onProjectChange = (e, task) => {
e.preventDefault()
setDefaultExecutor(user)
const projectId = e.target.value;
const project = uniqueProjects.length>0 ?uniqueProjects.find((uniqueProject) => uniqueProject.id === projectId):null;
console.log('change project ', project)
setCurrentProject(project)
let executorList=[]
if(project?.members){
for (let member of project.members){
executorList.push(member.user)
}
}
setExecutors(executorList)
// const { id } = task;
// const newTasks = recievedTasks.map((task) => {
// if (task.id === id) {
// const updated = { ...task };
// updated.project = project;
// updated.projectName =project.title? project.title:null;
// return updated;
// }
task.project = project;
task.projectName=project.title? project.title:null;
return task;
// });
// setRecievedTasks(newTasks);
};
const onExecutorChange = (e, task) => {
const executorId = e.target.value;
const executor = executors.find((executor) => executor.id === executorId);
// const { id } = task;
// const newTasks = recievedTasks.map((task) => {
// if (task.id === id) {
// const updated = { ...task };
// updated.executor = executor;
// updated.executorName = executor.displayName;
// return updated;
// }
// return task;
// });
// setRecievedTasks(newTasks);
task.executor = executor;
task.executorName = executor.displayName;
return task;
};
return ( return (
<> <>
<TableRow hover key={task.id}> <TableRow hover key={task.id}>
...@@ -159,7 +220,7 @@ const TableRowTask= ({ ...@@ -159,7 +220,7 @@ const TableRowTask= ({
task={task} task={task}
onChange={onExecutorChange} onChange={onExecutorChange}
name="executor" name="executor"
value={task.executor?.id} defaultValue={defaultExecutor?.id}
/> />
</TableCell> </TableCell>
) : ( ) : (
...@@ -180,19 +241,11 @@ const TableRowTask= ({ ...@@ -180,19 +241,11 @@ const TableRowTask= ({
task, task,
name: "author", name: "author",
value: task.author.displayName, value: task.author.displayName,
// onChange: onAuthorChange,
user:user user:user
}} }}
/> />
{task.isEditMode && task.author.id===user.id ? ( {task.isEditMode && task.author.id===user.id ? (
<TableCell> <TableCell>
{/* <MaterialUIPickers
task={task}
name="dateTimeStart"
onChange={onDateChange}
user={user}
/> */}
{/* <TableCell> */}
<Tooltip title="Перейти в календарь"> <Tooltip title="Перейти в календарь">
<IconButton <IconButton
onClick={(id) => { deleteHandle(task.id);}} onClick={(id) => { deleteHandle(task.id);}}
...@@ -200,7 +253,6 @@ const TableRowTask= ({ ...@@ -200,7 +253,6 @@ const TableRowTask= ({
<CalendarMonthIcon /> <CalendarMonthIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{/* </TableCell> */}
</TableCell> </TableCell>
) : ( ) : (
...@@ -236,15 +288,6 @@ const TableRowTask= ({ ...@@ -236,15 +288,6 @@ const TableRowTask= ({
)} )}
{/* <TableCell>
<MaterialUIPickers
task={task}
name="dateTimeStart"
onChange={onDateChange}
user={user}
/>
</TableCell> */}
{task.isEditMode && task.author.id===user.id ? ( {task.isEditMode && task.author.id===user.id ? (
<TableCell> <TableCell>
<MaterialUIPickers <MaterialUIPickers
...@@ -373,26 +416,7 @@ const TableRowTask= ({ ...@@ -373,26 +416,7 @@ const TableRowTask= ({
<TableCell <TableCell
// style={{width:'0%'}} // style={{width:'0%'}}
> >
{/* <Tooltip title="Редактировать Копию">
{task.isEditMode ? (
<IconButton
aria-label="done"
onClick={() => {
onToggleEditModeDone(dateTimeTask.id);
handleEditDateTimeTask(dateTimeTask);
}}
>
<Done />
</IconButton>
) : (
<IconButton
aria-label="edit"
onClick={() => onToggleEditMode(dateTimeTask.id)}
>
<Edit />
</IconButton>
)}
</Tooltip> */}
</TableCell > </TableCell >
{/* delete option datetimeTask */} {/* delete option datetimeTask */}
......
...@@ -27,6 +27,7 @@ export default function UsersTasks() { ...@@ -27,6 +27,7 @@ export default function UsersTasks() {
const user = useSelector((state) => state.users.user); const user = useSelector((state) => state.users.user);
const [executors, setExecutors]=useState([]) const [executors, setExecutors]=useState([])
// const [currentExecutor, setCurrentExecutor]= useState(task.executor.id?task.executor:'')
const [currentProject, setCurrentProject] = useState(null); const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]); const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false); const [addTaskForm, setAddTaskForm] = useState(false);
...@@ -39,6 +40,7 @@ export default function UsersTasks() { ...@@ -39,6 +40,7 @@ export default function UsersTasks() {
task: null, task: null,
}); });
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasksByMembership()); dispatch(fetchAllTasksByMembership());
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
...@@ -152,6 +154,7 @@ export default function UsersTasks() { ...@@ -152,6 +154,7 @@ export default function UsersTasks() {
const onToggleEditModeDone = (id) => { const onToggleEditModeDone = (id) => {
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
if (task.id === id) { if (task.id === id) {
console.log('toggledDone task ', task)
return { return {
...task, ...task,
isEditMode: false, isEditMode: false,
......
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