#110 create of task in MyTask fixed

parent e82c76a8
...@@ -176,7 +176,7 @@ export const taskFinderByDateTimeTaskId = async (dateTimeTaskId:string):Promise< ...@@ -176,7 +176,7 @@ export const taskFinderByDateTimeTaskId = async (dateTimeTaskId:string):Promise<
/**member finder by userId and projectId, return one task */ /**member finder by userId and projectId, return one task */
export const memberFinderById = async (userId:string, projectId:string)=>{ export const memberFinderById = async (userId:string, projectId:string):Promise<Member|null>=>{
const member = await dataSource const member = await dataSource
.getRepository(Member) .getRepository(Member)
.findOne({ .findOne({
...@@ -210,6 +210,17 @@ export let transporter = nodemailer.createTransport({ ...@@ -210,6 +210,17 @@ export let transporter = nodemailer.createTransport({
}) })
export const subtractHours= (date:Date, hours:number)=> {
const dateCopy = new Date(date);
console.log('dateCopy ', dateCopy)
dateCopy.setHours(dateCopy.getHours() - hours);
console.log('dateCopy afterset ', dateCopy)
return dateCopy;
}
export const FRONTEND_URL = 'localhost:3000'; export const FRONTEND_URL = 'localhost:3000';
...@@ -83,6 +83,8 @@ export class User extends BaseEntity implements IUser { ...@@ -83,6 +83,8 @@ export class User extends BaseEntity implements IUser {
@OneToMany(() => Member, (member: { user: User }) => member.user, {onDelete: 'CASCADE'}) @OneToMany(() => Member, (member: { user: User }) => member.user, {onDelete: 'CASCADE'})
members!: Member[]; members!: Member[];
// @OneToOne(()=>PasswordRecovery,)
@BeforeInsert() @BeforeInsert()
......
...@@ -5,7 +5,7 @@ import { User } from '../models/User'; ...@@ -5,7 +5,7 @@ import { User } from '../models/User';
import { Member, MemberRole } from '../models/Member'; import { Member, MemberRole } from '../models/Member';
import { Equal, In, Not } from 'typeorm'; import { Equal, In, Not } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask'; import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers'; import { auth, authAuthorOrExecutorOfTask, subtractHours, taskFinderById } from '../helpers';
import { Project } from '../models/Project'; import { Project } from '../models/Project';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -27,6 +27,17 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => { ...@@ -27,6 +27,17 @@ 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 ', dateTimeStart, 'dateTimeDue ', dateTimeDue, 'dateTimeDeadLine ', dateTimeDeadLine)
//** if dateTimeDue is null , then dateTimeDeadLine copied to dateTimeDue and dateTimeStart = dateTimeDue - 1 hour*/
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
let dateTimeDeadlineFinal= dateTimeDeadLine
if (!dateTimeDue && dateTimeDeadLine) {
dateTimeDueFinal = dateTimeDeadLine
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
}
console.log('dateTimeDueFinal ', dateTimeDueFinal, 'dateTimeStartFinal ', dateTimeStartFinal, 'dateTimeDeadLine ', dateTimeDeadLine,' dateTimeDeadlineFinal ', dateTimeDeadlineFinal)
const newTask = new Task(); const newTask = new Task();
newTask.title = title; newTask.title = title;
newTask.description = description; newTask.description = description;
...@@ -77,7 +88,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -77,7 +88,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
await newMember.save(); await newMember.save();
} }
} }
newTask.dateTimeDeadLine=dateTimeDeadLine; newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user; newTask.author= user;
if(newTask.project.title==="Личные дела"){ if(newTask.project.title==="Личные дела"){
newTask.executor=user; newTask.executor=user;
...@@ -86,11 +97,13 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -86,11 +97,13 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
} }
newTask.priority = priority; newTask.priority = priority;
await newTask.save(); await newTask.save();
if (dateTimeDeadlineFinal) {
const newDateTimeTask = new DateTimeTask(); const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart newDateTimeTask.dateTimeStart = dateTimeStartFinal
newDateTimeTask.dateTimeDue = dateTimeDue newDateTimeTask.dateTimeDue = dateTimeDueFinal
newDateTimeTask.task = newTask newDateTimeTask.task = newTask
await newDateTimeTask.save() await newDateTimeTask.save()
}
return res.send({newTask}); return res.send({newTask});
}) })
...@@ -170,13 +183,12 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -170,13 +183,12 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
relations:{ relations:{
executor:true, executor:true,
}, },
where:[ where:
{ {
executor:{ executor:{
id:userId id:userId
} }
}, },
]
}) })
return res.send({tasks}) return res.send({tasks})
}) })
...@@ -185,40 +197,13 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -185,40 +197,13 @@ 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>=>{
const user = req.body.user const user = req.body.user
// const tasks = await dataSource const projectsRawId = await dataSource
// .getRepository(Task) .getRepository(Project)
// .find({ .find({
// relations:{ select:{
// // project:true, id:true
// executor:true, },
// project:{
// members:{
// user:true
// }
// }
// },
// where:
// {
// executor:{
// id:user.id
// },
// project:{
// members:{
// user:user,
// // roleProject:Not(MemberRole.WATCHER)
// }
// }
// }
// }
// )
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:{
user:true
}},
where:{ where:{
title:Not(Equal("Не определено")), title:Not(Equal("Не определено")),
members:{ members:{
...@@ -229,13 +214,13 @@ const projects = await dataSource ...@@ -229,13 +214,13 @@ const projects = await dataSource
} }
} }
} }
) )
const projectsList= projects.map(project=> {return project.id})
console.log( 'projectsList ', projectsList)
const tasks = await dataSource const projectsList= projectsRawId.map(project=> {return project.id})
.getRepository(Task)
.find( const tasks = await dataSource
.getRepository(Task)
.find(
{relations:{ {relations:{
author:true, author:true,
executor:true, executor:true,
...@@ -245,34 +230,21 @@ const tasks = await dataSource ...@@ -245,34 +230,21 @@ const tasks = await dataSource
executor:{ executor:{
id:user.id id:user.id
}, },
// project:{
// id:In(projectsList)
// }
} }
} }
) )
// console.log('tasks ', tasks) const projects = await dataSource
// console.log('projects ', projects) .getRepository(Project)
// const projectsList= tasks.map(task=> {return task.project?.id}) .find({
// console.log( 'projectsList ', projectsList) relations:{
// const projects= await dataSource members:true
// .getRepository(Project) },
// .find({relations:{ where:{
// members:{ id:In(projectsList)
// user:true }
// } })
// },
// where:{
// id:In(
// projectsList,
// ),
// title:Not(Equal("Не определено"))
// }
// })
// return res.send({
// projects})
return res.send({tasks, projects}) return res.send({tasks, projects})
}) })
/**return tasks & users of projects in which current user is involved, search by token*/ /**return tasks & users of projects in which current user is involved, search by token*/
...@@ -336,7 +308,9 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=> ...@@ -336,7 +308,9 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**change of task by task id */ /**change of task by task id */
router.put('/:taskId',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> { router.put('/:taskId',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
const {taskId} = req.params const {taskId} = req.params
const {authorStatus,executorStatus,title,description,note, archive,project,dateTimeTaskId,dateTimeStart,dateTimeDue,executor,accomplish,dateTimeDeadLine, dateTimeFactDeadLine,priority} = req.body; const {authorStatus,executorStatus,title,description,note, archive,project,dateTimeTaskId,dateTimeStart,
dateTimeDue,executor,accomplish,dateTimeDeadLine, dateTimeFactDeadLine,priority} = req.body;
console.log('dateTimeTaskId ', dateTimeTaskId)
const task = await taskFinderById(taskId) const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'}) if (!task) return res.status(404).send({Message:'task not found'})
let dateTimeTask = null; let dateTimeTask = null;
......
...@@ -8,18 +8,18 @@ import MultipleSelect from '../../components/UI/MultipleSelect/MultipleSelect'; ...@@ -8,18 +8,18 @@ import MultipleSelect from '../../components/UI/MultipleSelect/MultipleSelect';
import Add from "@mui/icons-material/Add"; import Add from "@mui/icons-material/Add";
import Close from "@mui/icons-material/Close"; import Close from "@mui/icons-material/Close";
export default function MyTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) { export default function MyTaskToolBar({projects,onClose,projectIdListForTaskSelect,setProjectIdListForTaskSelect,formStatus,onClick}) {
let projectsFilter = let projectsFilter =
<></> <></>
if (projects) { if (Array.isArray(projects)) {
projectsFilter= projectsFilter=
<MultipleSelect <MultipleSelect
projects={projects} projects={projects}
onClose={onClose} onClose={onClose}
projectName={projectName} projectName={projectIdListForTaskSelect}
setProjectName={setProjectName} setProjectName={setProjectIdListForTaskSelect}
/> />
} }
......
...@@ -35,7 +35,7 @@ export default function NewTaskForm({ projects, setAddTaskForm }) { ...@@ -35,7 +35,7 @@ export default function NewTaskForm({ projects, setAddTaskForm }) {
dateTimeDeadLine: null, dateTimeDeadLine: null,
dateTimeTasks: [], dateTimeTasks: [],
dateTimeDue: null, dateTimeDue: null,
project: projects[0], project: null,
accomplish: "opened", accomplish: "opened",
priority: "B", priority: "B",
author: { id: user.id }, author: { id: user.id },
......
...@@ -6,7 +6,12 @@ import FormControl from "@mui/material/FormControl"; ...@@ -6,7 +6,12 @@ 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)
// console.log('select value ', value)
return ( return (
<Box sx={{ minWidth: 60, m: 0}}> <Box sx={{ minWidth: 60, m: 0}}>
<FormControl fullWidth> <FormControl fullWidth>
...@@ -19,11 +24,11 @@ export default function BasicSelect({value,label,name,onChange,task,items}) { ...@@ -19,11 +24,11 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
name={name} name={name}
onChange={(e) => onChange(e, task)} onChange={(e) => onChange(e, task)}
> >
{items.map((item,index) => ( {items ?items.map((item,index) => (
<MenuItem key={index} value={item.value}> <MenuItem key={index} value={item.value}>
{item.title} {item.title}
</MenuItem> </MenuItem>
))} )):<></>}
</Select> </Select>
</FormControl> </FormControl>
</Box> </Box>
......
...@@ -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: projects[0], project: [],
accomplish: "opened", accomplish: "opened",
priority: "B", priority: "B",
author: { id: user.id }, author: { id: user.id },
...@@ -240,13 +240,7 @@ export const header = [ ...@@ -240,13 +240,7 @@ export const header = [
disablePadding: true, disablePadding: true,
label: "Приоритет", label: "Приоритет",
}, },
// { {
// id: "createdAt",
// numeric: true,
// disablePadding: false,
// label: "Дата создания",
// },
{
id: "title", id: "title",
numeric: false, numeric: false,
disablePadding: false, disablePadding: false,
...@@ -266,7 +260,7 @@ export const header = [ ...@@ -266,7 +260,7 @@ export const header = [
label: "Исполнитель", label: "Исполнитель",
}, },
{ {
id: "dateTimeDue", id: "dateTimeDeadLine",
numeric: true, numeric: true,
disablePadding: false, disablePadding: false,
label: "Дедлайн", label: "Дедлайн",
......
...@@ -8,7 +8,7 @@ import MultipleSelect from '../UI/MultipleSelect/MultipleSelect'; ...@@ -8,7 +8,7 @@ import MultipleSelect from '../UI/MultipleSelect/MultipleSelect';
import Add from "@mui/icons-material/Add"; import Add from "@mui/icons-material/Add";
import Close from "@mui/icons-material/Close"; import Close from "@mui/icons-material/Close";
export default function UsersTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) { export default function UsersTaskToolBar({projects,onClose,projectIdListForTaskSelect,setProjectIdListForTaskSelect,formStatus,onClick}) {
let projectsFilter = let projectsFilter =
<></> <></>
...@@ -18,8 +18,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec ...@@ -18,8 +18,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec
<MultipleSelect <MultipleSelect
projects={projects} projects={projects}
onClose={onClose} onClose={onClose}
projectName={projectName} projectName={projectIdListForTaskSelect}
setProjectName={setProjectName} setProjectName={setProjectIdListForTaskSelect}
/> />
} }
......
...@@ -7,6 +7,7 @@ import PersonIcon from '@mui/icons-material/Person'; ...@@ -7,6 +7,7 @@ import PersonIcon from '@mui/icons-material/Person';
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { Alert, Avatar, Container, Typography } from "@mui/material"; import { Alert, Avatar, Container, Typography } from "@mui/material";
import ResetPasswordForm from "../../components/UserForm/ResetPasswordForm"; import ResetPasswordForm from "../../components/UserForm/ResetPasswordForm";
import axios from "axios";
const StyledContainer = styled(Container)` const StyledContainer = styled(Container)`
padding-top: 30px; padding-top: 30px;
......
...@@ -34,7 +34,6 @@ export default function EnhancedTable() { ...@@ -34,7 +34,6 @@ export default function EnhancedTable() {
open: false, open: false,
task: null, task: null,
}); });
// const [projects, setProjects] = useState(["1", "2"]);
// useEffect(() => { // useEffect(() => {
// dispatch(fetchAllTasks()); // dispatch(fetchAllTasks());
...@@ -42,14 +41,15 @@ export default function EnhancedTable() { ...@@ -42,14 +41,15 @@ export default function EnhancedTable() {
// }, [dispatch]); // }, [dispatch]);
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks());
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks); setRecievedTasks(tasks);
} }
}, [ tasks?.length]); }, [ tasks?.length,addTaskForm, setAddTaskForm, dispatch]);
console.log('tasks ', tasks, 'projects ', projects)
useEffect(() => { // useEffect(() => {
dispatch(fetchAllTasks()); // dispatch(fetchAllTasks());
}, [addTaskForm, setAddTaskForm, dispatch]); // }, [addTaskForm, setAddTaskForm, dispatch]);
...@@ -112,7 +112,7 @@ export default function EnhancedTable() { ...@@ -112,7 +112,7 @@ export default function EnhancedTable() {
const onProjectChange = (e, task) => { const onProjectChange = (e, task) => {
const value = e.target.value; const value = e.target.value;
const project = uniqueProjects.find((e) => e.id === value); const project = projects.find((e) => e.id === value);
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
if (task.id === id) { if (task.id === id) {
...@@ -183,46 +183,33 @@ export default function EnhancedTable() { ...@@ -183,46 +183,33 @@ export default function EnhancedTable() {
}; };
// ++++++++фильтрация по проектам+++++++++++++++ // ++++++++фильтрация по проектам+++++++++++++++
const [projectName, setProjectName] = React.useState([]); const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = React.useState([]);
const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false); const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false);
const onClose = (projectName) => { const onClose=(projectIdListForTaskSelect)=>{
let tasksFilteredByProject = tasks; console.log('projectIdListForTaskSelect ', projectIdListForTaskSelect)
if (projectName.length > 0) { let tasksFilteredByProject = tasks
tasksFilteredByProject = tasks.filter((task) => if (projectIdListForTaskSelect.length>0) {
projectName.includes(task.project?.title) tasksFilteredByProject = tasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
);
}
setRecievedTasks(tasksFilteredByProject);
setFilterProjectTumbler(true);
};
const rawProjects = tasks?.map((task) => task.project);
const filterProjectsNamesFromTasks = () => {
if (tasks && tasks?.length > 0) {
let rawSetProjectNames = [];
for (let project of rawProjects) {
if (project === null) {
} else {
rawSetProjectNames.push(project.title);
} }
console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true)
} }
let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
// setProjects(uniqueTitlesProjects);
}
};
const uniqueProjects = rawProjects?.reduce((results, value, index) => { // const rawProjects = tasks?.map((task) => task.project);
const exist = results.find((v) => {
return v !== null && v.id === value?.id;
});
if (!exist && value !== null) {
results.push(value);
}
return results;
}, []);
console.log('tasks', tasks) // const uniqueProjects = rawProjects?.reduce((results, value, index) => {
// const exist = results.find((v) => {
// return v !== null && v.id === value?.id;
// });
// if (!exist && value !== null) {
// results.push(value);
// }
// return results;
// }, []);
// console.log('tasks', tasks)
if ( if (
tasks && tasks &&
...@@ -238,13 +225,13 @@ console.log('tasks', tasks) ...@@ -238,13 +225,13 @@ console.log('tasks', tasks)
formStatus={addTaskForm} formStatus={addTaskForm}
projects={projects} projects={projects}
onClose={onClose} onClose={onClose}
projectName={projectName} projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectName={setProjectName} setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
/> />
{addTaskForm ? ( {addTaskForm ? (
<NewTaskForm <NewTaskForm
projects={uniqueProjects} projects={projects}
setAddTaskForm={() => setAddTaskForm(false)} setAddTaskForm={() => setAddTaskForm(false)}
/> />
) : null} ) : null}
...@@ -273,8 +260,7 @@ console.log('tasks', tasks) ...@@ -273,8 +260,7 @@ console.log('tasks', tasks)
onChange={onChange} onChange={onChange}
onModalOpen={onModalOpen} onModalOpen={onModalOpen}
onProjectChange={onProjectChange} onProjectChange={onProjectChange}
uniqueProjects={uniqueProjects} uniqueProjects={projects}
onAuthorChange={onAuthorChange}
onDateChange={onDateChange} onDateChange={onDateChange}
onToggleEditMode={onToggleEditMode} onToggleEditMode={onToggleEditMode}
onToggleEditModeDone={onToggleEditModeDone} onToggleEditModeDone={onToggleEditModeDone}
......
...@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux"; ...@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux";
import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal"; import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal";
import moment from "moment"; import moment from "moment";
import UsersTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar"; import UsersTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar";
import { fetchAllTasks, deleteTask,editTask, deleteDateTimeTask , fetchAllTasksByMembership} from "../../store/actions/tasksActions"; import { deleteTask, editTask, deleteDateTimeTask , fetchAllTasksByMembership} from "../../store/actions/tasksActions";
import NewTaskForm from "../../components/UsersTasksCompoments/NewTaskForm"; import NewTaskForm from "../../components/UsersTasksCompoments/NewTaskForm";
import TableRowTask from "../../components/UsersTasksCompoments/TableRowTask/TableRowTask"; import TableRowTask from "../../components/UsersTasksCompoments/TableRowTask/TableRowTask";
import UsersTasksHeader from "./UsersTasksHeader/UsersTasksHeader"; import UsersTasksHeader from "./UsersTasksHeader/UsersTasksHeader";
...@@ -198,12 +198,6 @@ export default function UsersTasks() { ...@@ -198,12 +198,6 @@ export default function UsersTasks() {
dispatch(deleteDateTimeTask(dateTimeTaskId)) dispatch(deleteDateTimeTask(dateTimeTaskId))
} }
const handleEditDateTimeTask=(dateTimeTask)=>{
console.log('edit by dateTImeTask')
// dispatch(handleEditDateTimeTask(dateTimeTask))
}
const onModalOpen = (event, task) => { const onModalOpen = (event, task) => {
event.stopPropagation(); event.stopPropagation();
setModal({ ...modal, open: true, id: task.id }); setModal({ ...modal, open: true, id: task.id });
...@@ -214,48 +208,20 @@ export default function UsersTasks() { ...@@ -214,48 +208,20 @@ export default function UsersTasks() {
}; };
// ++++++++фильтрация по проектам+++++++++++++++ // ++++++++фильтрация по проектам+++++++++++++++
const [projectName, setProjectName] = React.useState([]); const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = React.useState([]);
const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false); const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false);
const onClose=(projectName)=>{ const onClose=(projectIdListForTaskSelect)=>{
console.log('projectName ', projectName) console.log('projectIdListForTaskSelect ', projectIdListForTaskSelect)
let tasksFilteredByProject = tasks let tasksFilteredByProject = tasks
if (projectName.length>0) { if (projectIdListForTaskSelect.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectName.includes(task.project?.id)) tasksFilteredByProject = tasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
} }
console.log('tasksFilteredByProject ', tasksFilteredByProject) console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject) setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true) setFilterProjectTumbler(true)
} }
const rawProjects= tasks?.map(task=>task.project)
// const filterProjectsNamesFromTasks = ()=>{
// if (tasks && tasks?.length > 0) {
// let rawSetProjectNames = []
// for (let project of rawProjects){
// if (project===null){
// } else{
// rawSetProjectNames.push(project.title)
// }
// }
// let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
// setProjects(uniqueTitlesProjects)
// }
// }
const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => {
return v !== null && v.id === value?.id
});
if (!exist && value !== null) {
results.push(value);
}
return results;
}, []);
if ( if (
tasks && tasks &&
...@@ -271,8 +237,8 @@ export default function UsersTasks() { ...@@ -271,8 +237,8 @@ export default function UsersTasks() {
formStatus={addTaskForm} formStatus={addTaskForm}
projects={projects} projects={projects}
onClose={onClose} onClose={onClose}
projectName={projectName} projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectName={setProjectName} setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
/> />
{addTaskForm ? ( {addTaskForm ? (
...@@ -311,8 +277,7 @@ export default function UsersTasks() { ...@@ -311,8 +277,7 @@ export default function UsersTasks() {
onProjectChange={onProjectChange} onProjectChange={onProjectChange}
executors={executors} executors={executors}
onExecutorChange={onExecutorChange} onExecutorChange={onExecutorChange}
uniqueProjects={uniqueProjects} uniqueProjects={projects}
// onAuthorChange={onAuthorChange}
onDateChange={onDateChange} onDateChange={onDateChange}
onToggleEditMode={onToggleEditMode} onToggleEditMode={onToggleEditMode}
onToggleEditModeDone={onToggleEditModeDone} onToggleEditModeDone={onToggleEditModeDone}
......
...@@ -30,8 +30,8 @@ const fetchCalendarTasksSuccess = (tasks) => { ...@@ -30,8 +30,8 @@ const fetchCalendarTasksSuccess = (tasks) => {
return {type: FETCH_CALENDAR_TASKS_SUCCESS, tasks} return {type: FETCH_CALENDAR_TASKS_SUCCESS, tasks}
}; };
const fetchAllTasksSuccess = (tasks) => { const fetchAllTasksSuccess = (tasks,projects) => {
return {type: FETCH_ALL_TASKS_SUCCESS, tasks} return {type: FETCH_ALL_TASKS_SUCCESS, tasks, projects}
}; };
...@@ -55,8 +55,8 @@ export const fetchAllTasks = () => { ...@@ -55,8 +55,8 @@ export const fetchAllTasks = () => {
return async (dispatch) => { return async (dispatch) => {
dispatch(fetchCalendarTasksRequest()); dispatch(fetchCalendarTasksRequest());
try { try {
const response = await axios.get("/tasks"); const response = await axios.get("/tasks/my");
dispatch(fetchAllTasksSuccess(response.data.tasks)) dispatch(fetchAllTasksSuccess(response.data.tasks,response.data.projects))
} catch (error) { } catch (error) {
dispatch(fetchCalendarTasksFailure(error.response.data)); dispatch(fetchCalendarTasksFailure(error.response.data));
} }
......
...@@ -78,7 +78,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -78,7 +78,7 @@ const tasksReduсer = (state = initialState, action) => {
}) })
return {...state, loading: false, calendarTasks: newTasksWithInfoForCell}; return {...state, loading: false, calendarTasks: newTasksWithInfoForCell};
case FETCH_ALL_TASKS_SUCCESS: case FETCH_ALL_TASKS_SUCCESS:
return {...state, loading: false, tasks: action.tasks}; return {...state, loading: false, tasks: action.tasks, projects:action.projects};
case FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS: case FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS:
return {...state, loading: false, tasks: action.tasks, projects:action.projects}; return {...state, loading: false, tasks: action.tasks, projects:action.projects};
case FETCH_CALENDAR_TASKS_FAILURE: case FETCH_CALENDAR_TASKS_FAILURE:
......
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