#110 select project is fixed

parent c79bfce2
...@@ -62,7 +62,6 @@ router.get('/all-fields/', async (req : Request, res : Response):Promise<object> ...@@ -62,7 +62,6 @@ router.get('/all-fields/', async (req : Request, res : Response):Promise<object>
}, },
} }
}) })
console.log('all fields users ', users)
return res.send({users}) return res.send({users})
}) })
......
...@@ -61,11 +61,11 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN ...@@ -61,11 +61,11 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
> >
{projects?.map((project) => ( {projects?.map((project) => (
<MenuItem <MenuItem
key={project} key={project.id}
value={project} value={project.id}
style={getStyles(project, projectName, theme)} style={getStyles(project, project.title, theme)}
> >
{project} {project.title}
</MenuItem> </MenuItem>
))} ))}
</Select> </Select>
......
...@@ -8,12 +8,12 @@ import MultipleSelect from '../UI/MultipleSelect/MultipleSelect'; ...@@ -8,12 +8,12 @@ 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 MyTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) { export default function UsersTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) {
let projectsFilter = let projectsFilter =
<></> <></>
if (projects) { if (Array.isArray(projects)) {
projectsFilter= projectsFilter=
<MultipleSelect <MultipleSelect
projects={projects} projects={projects}
......
...@@ -11,7 +11,7 @@ import { useState, useEffect } from "react"; ...@@ -11,7 +11,7 @@ import { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux"; 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 MyTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar"; import UsersTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar";
import { fetchAllTasks, deleteTask,editTask, deleteDateTimeTask , fetchAllTasksByMembership} from "../../store/actions/tasksActions"; import { fetchAllTasks, 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";
...@@ -45,11 +45,13 @@ export default function UsersTasks() { ...@@ -45,11 +45,13 @@ export default function UsersTasks() {
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks); setRecievedTasks(tasks);
} }
}, [dispatch, tasks?.length]); }, [dispatch,
tasks?.length,
addTaskForm, setAddTaskForm]);
useEffect(() => { // useEffect(() => {
dispatch(fetchAllTasksByMembership()); // dispatch(fetchAllTasksByMembership());
}, [addTaskForm, setAddTaskForm]); // }, [addTaskForm, setAddTaskForm]);
...@@ -112,14 +114,21 @@ useEffect(() => { ...@@ -112,14 +114,21 @@ useEffect(() => {
const onProjectChange = (e, task) => { const onProjectChange = (e, task) => {
const projectId = e.target.value; const projectId = e.target.value;
const project = projects.find((uniqueProject) => uniqueProject.id === projectId); const project = projects.length>0 ?projects.find((uniqueProject) => uniqueProject.id === projectId):null;
setCurrentProject(project) setCurrentProject(project)
if(project?.members){
for (let member of project.members){
setExecutors([...executors, member.user])
}
console.log('executors ', executors)
}
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
if (task.id === id) { if (task.id === id) {
const updated = { ...task }; const updated = { ...task };
updated.project = project; updated.project = project;
updated.projectName = project.title; updated.projectName =project.title? project.title:null;
return updated; return updated;
} }
return task; return task;
...@@ -209,10 +218,12 @@ useEffect(() => { ...@@ -209,10 +218,12 @@ useEffect(() => {
const onClose=(projectName)=>{ const onClose=(projectName)=>{
console.log('projectName ', projectName)
let tasksFilteredByProject = tasks let tasksFilteredByProject = tasks
if (projectName.length>0) { if (projectName.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectName.includes(task.project?.title)) tasksFilteredByProject = tasks.filter(task=>projectName.includes(task.project?.id))
} }
console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject) setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true) setFilterProjectTumbler(true)
} }
...@@ -244,7 +255,6 @@ useEffect(() => { ...@@ -244,7 +255,6 @@ useEffect(() => {
return results; return results;
}, []); }, []);
console.log('tasks', tasks)
if ( if (
tasks && tasks &&
...@@ -255,7 +265,7 @@ console.log('tasks', tasks) ...@@ -255,7 +265,7 @@ console.log('tasks', tasks)
return ( return (
<Box sx={{ width: "fullwidth" }}> <Box sx={{ width: "fullwidth" }}>
<Paper sx={{ width: "100%", mb: 2 }}> <Paper sx={{ width: "100%", mb: 2 }}>
<MyTaskToolBar <UsersTaskToolBar
onClick={() => setAddTaskForm(!addTaskForm)} onClick={() => setAddTaskForm(!addTaskForm)}
formStatus={addTaskForm} formStatus={addTaskForm}
projects={projects} projects={projects}
...@@ -275,7 +285,7 @@ console.log('tasks', tasks) ...@@ -275,7 +285,7 @@ console.log('tasks', tasks)
<TableContainer> <TableContainer>
<Table sx={{ minWidth: 600 }} aria-labelledby="tableTitle"> <Table sx={{ minWidth: 600 }} aria-labelledby="tableTitle" size='small'>
<UsersTasksHeader <UsersTasksHeader
order={order} order={order}
orderBy={orderBy} orderBy={orderBy}
...@@ -294,7 +304,6 @@ console.log('tasks', tasks) ...@@ -294,7 +304,6 @@ console.log('tasks', tasks)
task={task} task={task}
deleteHandle={deleteHandle} deleteHandle={deleteHandle}
handleEditTask ={handleEditTask} handleEditTask ={handleEditTask}
handleEditDateTimeTask={handleEditDateTimeTask}
deleteDateTimeTask={deleteDateTimeTaskHandle} deleteDateTimeTask={deleteDateTimeTaskHandle}
onChange={onChange} onChange={onChange}
onModalOpen={onModalOpen} onModalOpen={onModalOpen}
......
...@@ -64,8 +64,8 @@ export const fetchAllTasks = () => { ...@@ -64,8 +64,8 @@ export const fetchAllTasks = () => {
}; };
//**fetch tasks for table UsersTasks, start*/ //**fetch tasks for table UsersTasks, start*/
const fetchAllTasksByMembershipSuccess = (tasks) => { const fetchAllTasksByMembershipSuccess = (tasks, projects) => {
return {type: FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, tasks} return {type: FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, tasks, projects}
}; };
...@@ -75,7 +75,7 @@ export const fetchAllTasksByMembership = () => { ...@@ -75,7 +75,7 @@ export const fetchAllTasksByMembership = () => {
dispatch(fetchCalendarTasksRequest()); dispatch(fetchCalendarTasksRequest());
try { try {
const response = await axios.get("/tasks/users-tasks"); const response = await axios.get("/tasks/users-tasks");
dispatch(fetchAllTasksByMembershipSuccess(response.data.tasks)) dispatch(fetchAllTasksByMembershipSuccess(response.data.tasks, response.data.projects))
} catch (error) { } catch (error) {
dispatch(fetchCalendarTasksFailure(error.response.data)); dispatch(fetchCalendarTasksFailure(error.response.data));
} }
......
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