Commit 604159dd authored by Ermolaev Timur's avatar Ermolaev Timur

#154 Изменил все запросы под текущую таблицу

parent 9021b8a9
......@@ -29,6 +29,7 @@ router.get('/', 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, calendar} = req.body;
console.log('dateTimeStart \n', dateTimeStart, "dateTimeDue\n", dateTimeDue, 'dateTimeDeadLine\n ', dateTimeDeadLine)
console.log(req.body)
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
let dateTimeDeadlineFinal= dateTimeDeadLine
......
import { Box, Divider, Grid, IconButton, TextField, Tooltip, Typography, } from "@mui/material";
import { styled } from '@mui/material/styles';
import { memo, useMemo } from "react";
import { memo } from "react";
import { priorities } from "../../../../constants";
import CustomSelect from "../../../UI/СustomSelect/СustomSelect"
import MaterialUIPickers from "../DateTimePicker/DateTimePicker";
......@@ -18,14 +18,6 @@ const StyledTooltip = styled(({ className, ...props }) => (
function MyTaskNewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChangeHandler, createNewTaskHandler }) {
const workers = useMemo(() => {
if (newTask?.project) {
return newTask?.project?.members.map((member) => { return { value: member.user, text: member.user.displayName } })
} else {
return [{ value: '', text: 'Выберите проект' }]
}
}, [newTask?.project])
return (
<Box sx={{
......@@ -44,11 +36,10 @@ function MyTaskNewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, all
}}>
<Grid container padding={2}>
<Grid item xs={1}>Приоритеты</Grid>
<Grid item xs={3.5}>Заголовок</Grid>
<Grid item xs={5}>Заголовок</Grid>
<Grid item xs={2}>Проект</Grid>
<Grid item xs={2}>Исполнитель</Grid>
<Grid item xs={3}>Дедлайн</Grid>
<Grid item xs={0.5}></Grid>
<Grid item xs={1}></Grid>
</Grid>
<Grid container padding={2} alignItems='center'>
<Grid item xs={1}>
......@@ -63,7 +54,7 @@ function MyTaskNewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, all
sx={{ width: '90%' }}
/>
</Grid>
<Grid item xs={3.5}>
<Grid item xs={5}>
<StyledTooltip
title={<TextField
id="task-description"
......@@ -98,17 +89,6 @@ function MyTaskNewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, all
sx={{ width: '90%' }}
/>
</Grid>
<Grid item xs={2}>
<CustomSelect
value={newTask.executor}
name={'executor'}
variant={'outlined'}
onChange={onChangeNewTaskHandler}
id={'executor'}
items={workers}
sx={{ width: '90%' }}
/>
</Grid>
<Grid item xs={3}>
<MaterialUIPickers
task={newTask}
......@@ -116,7 +96,7 @@ function MyTaskNewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, all
onChange={onDateChangeHandler}
/>
</Grid>
<Grid item xs={0.5} >
<Grid item xs={1} >
<IconButton disabled={!isValidate(newTask.title, newTask.description)} onClick={createNewTaskHandler}>
<Save />
</IconButton>
......
import { TableCell, TextField, Tooltip } from "@mui/material";
import moment from "moment";
import { memo, useMemo } from "react";
import { memo } from "react";
import { accomplishStatuses, priorities } from "../../../../../../constants";
import CustomSelect from "../../../../../UI/СustomSelect/СustomSelect"
import { styled } from '@mui/material/styles';
......@@ -15,16 +15,6 @@ const StyledTooltip = styled(({ className, ...props }) => (
`;
function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTask, allUserProjectsForModalTask, onDateChangeEditHandler, user }) {
const workers = useMemo(() => {
if (currentTask?.project) {
currentTask.project = allUserProjectsForModalTask.find((project) => project?.value?.id === currentTask?.project?.id)?.value
const arrUsers = currentTask?.project?.members.map((member) => { return { value: member.user, text: member.user.displayName } })
arrUsers.push({ value: '', text: 'Никто' })
return arrUsers
} else {
return [{ value: '', text: 'Выберите проект' }]
}
}, [allUserProjectsForModalTask, currentTask])
return (
<>
......@@ -45,7 +35,7 @@ function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTa
<TableCell sx={{ width: '10%' }}>{moment(currentTask.createdAt).format('DD.MM.YYYY')}</TableCell>
<Tooltip title={currentTask.description}>
<TableCell sx={{ width: '25%', overflow: 'hidden', textOverflow: 'ellipsis' }}>
<TableCell sx={{ width: '28%', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{user.id === currentTask.author.id ?
<StyledTooltip
title={<TextField
......@@ -72,7 +62,7 @@ function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTa
: currentTask.title}
</TableCell>
</Tooltip>
<TableCell sx={{ width: '10%' }}>
<TableCell sx={{ width: '12%' }}>
{user.id === currentTask.author.id ?
<CustomSelect
value={currentTask.project}
......@@ -85,7 +75,7 @@ function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTa
/>
: currentTask.projectTitle}
</TableCell>
<TableCell sx={{ width: '8%' }}>{currentTask.authorName}</TableCell>
<TableCell sx={{ width: '11%' }}>{currentTask.authorName}</TableCell>
<TableCell sx={{ width: '13%' }}>
{dateTimeTasks}
......
......@@ -164,12 +164,12 @@ function MyTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHandle
<TableCell sx={{ width: '4%' }}>{row.priority ? row.priority : null}</TableCell>
<TableCell sx={{ width: '10%' }}>{moment(row.createdAt).format('DD.MM.YYYY')}</TableCell>
<Tooltip title={row.description}>
<TableCell sx={{ width: '25%' }}>
<TableCell sx={{ width: '28%' }}>
{row.title}
</TableCell>
</Tooltip>
<TableCell sx={{ width: '10%' }}>{row.projectTitle}</TableCell>
<TableCell sx={{ width: '8%' }}>{row.authorName}</TableCell>
<TableCell sx={{ width: '12%' }}>{row.projectTitle}</TableCell>
<TableCell sx={{ width: '11%' }}>{row.authorName}</TableCell>
<TableCell sx={{ width: '13%' }}>
{dateTimeTasks}
......
......@@ -24,7 +24,7 @@ const headCells = [
label: "Заголовок",
canSort: true,
style: {
width: '25%'
width: '28%'
}
},
{
......@@ -32,7 +32,7 @@ const headCells = [
label: "Проект",
canSort: true,
style: {
width: '10%'
width: '12%'
}
},
{
......@@ -40,7 +40,7 @@ const headCells = [
label: "Автор",
canSort: true,
style: {
width: '8%'
width: '11%'
}
},
{
......
......@@ -28,7 +28,7 @@ return (
id="tableTitle"
component="div"
>
Задачи сотрудников
Мои задачи
</Typography>
{projectsFilter}
<CreateTaskFromButton
......
......@@ -2,17 +2,18 @@ import Paper from '@mui/material/Paper';
import MyTasksTableToolbar from '../../components/MyTasksCompoments/MyTasksTableToolbar/MyTasksTableToolbar';
import MyTasksTablePagination from '../../components/MyTasksCompoments/MyTasksTablePagination/MyTasksTablePagination';
import MyTasksTableContainer from '../../components/MyTasksCompoments/MyTasksTableContainer/MyTasksTableContainer';
import { activateCreateCopyTasksMode, addTaskToUserTasksTable, deleteDateTimeTaskUsers, deleteTaskUsers, editTaskUsers, fetchAllTasksByMembership, sortTaskByProjects } from '../../store/actions/tasksActions';
import { activateCreateCopyTasksMode, fetchAllTasks, sortTaskByProjects, addTask, deleteTask, deleteDateTimeTask, editTask } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useCallback, useEffect, useState } from 'react';
import { fetchAllUserProjects, fetchProjects } from '../../store/actions/projectsActions';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
export default function EnhancedTable() {
export default function MyTasks() {
const dispatch = useDispatch();
const navigate = useNavigate()
const { user } = useSelector((state) => state.users);
const { tasks, sortedTasks } = useSelector((state) => state.tasks, shallowEqual);
const { allUserProjectsForModalTask, projects } = useSelector(state => state.projects, shallowEqual)
......@@ -21,7 +22,6 @@ export default function EnhancedTable() {
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: null,
})
......@@ -30,7 +30,6 @@ export default function EnhancedTable() {
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: null,
})
......@@ -42,11 +41,11 @@ export default function EnhancedTable() {
const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = useState([]);
useEffect(() => {
dispatch(fetchAllTasksByMembership());
dispatch(fetchAllTasks());
dispatch(fetchAllUserProjects())
dispatch(fetchProjects())
}, [dispatch]);
useEffect(() => {
dispatch(sortTaskByProjects(projectIdListForTaskSelect))
}, [dispatch, projectIdListForTaskSelect]);
......@@ -114,7 +113,6 @@ export default function EnhancedTable() {
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: null
})
}
......@@ -122,36 +120,31 @@ export default function EnhancedTable() {
}, [addFormStatus])
const createNewTaskHandler = useCallback(() => {
if (newTask.priority === '' || newTask.project === '' || newTask.executor === '') {
const task = {
...newTask,
priority: newTask.priority ? newTask.priority : null,
project: newTask.project ? newTask.project : null,
executor: newTask.executor ? newTask.executor : null,
dateTimeDeadLine: new Date(newTask.dateTimeDeadLine) instanceof Date && !isNaN(new Date(newTask.dateTimeDeadLine)) ? newTask.dateTimeDeadLine : null
}
dispatch(addTaskToUserTasksTable(task))
} else {
dispatch(addTaskToUserTasksTable(newTask))
const task = {
...newTask,
priority: newTask.priority ? newTask.priority : null,
project: newTask.project ? newTask.project : null,
executor: user,
dateTimeDeadLine: new Date(newTask.dateTimeDeadLine) instanceof Date && !isNaN(new Date(newTask.dateTimeDeadLine)) ? newTask.dateTimeDeadLine : null
}
dispatch(addTask(task))
setNewTask({
priority: '',
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: null
})
setAddFormStatus((prevState) => { return !prevState })
}, [dispatch, newTask])
}, [dispatch, newTask, user])
console.log(currentTask)
const deleteTaskHandler = useCallback((id) => {
dispatch(deleteTaskUsers(id))
dispatch(deleteTask(id))
}, [dispatch])
const deleteCopyTaskHandler = useCallback((id) => {
dispatch(deleteDateTimeTaskUsers(id))
dispatch(deleteDateTimeTask(id))
}, [dispatch])
const calendarOpen = useCallback((task) => {
......@@ -159,27 +152,22 @@ export default function EnhancedTable() {
}, [dispatch, navigate])
const editCurrentTaskHandler = useCallback(() => {
if (currentTask.priority === '' || currentTask.project === '' || currentTask.executor === '' || !Object.keys(currentTask.executor).length) {
const task = {
...currentTask,
priority: currentTask.priority ? currentTask.priority : null,
project: currentTask.project ? currentTask.project : null,
executor: currentTask.executor && currentTask.executor?.id ? currentTask.executor : null,
dateTimeDeadLine: new Date(currentTask.dateTimeDeadLine) instanceof Date && !isNaN(new Date(currentTask.dateTimeDeadLine)) ? currentTask.dateTimeDeadLine : null
}
dispatch(editTaskUsers(task))
} else {
dispatch(editTaskUsers(currentTask))
const task = {
...currentTask,
priority: currentTask.priority ? currentTask.priority : null,
project: currentTask.project ? currentTask.project : null,
executor: user,
dateTimeDeadLine: new Date(currentTask.dateTimeDeadLine) instanceof Date && !isNaN(new Date(currentTask.dateTimeDeadLine)) ? currentTask.dateTimeDeadLine : null
}
dispatch(editTask(task))
setCurrentTask({
priority: '',
title: '',
project: '',
description: '',
executor: '',
dateTimeDeadLine: null
})
}, [dispatch, currentTask])
}, [dispatch, currentTask, user])
const onCloseFilterByProjects = useCallback((listProjectIds) => {
setProjectIdListForTaskSelect(listProjectIds)
......
......@@ -9,7 +9,7 @@ import { fetchAllUserProjects, fetchProjects } from '../../store/actions/project
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
export default function EnhancedTable() {
export default function UsersTasks() {
const dispatch = useDispatch();
const navigate = useNavigate()
......
......@@ -135,7 +135,7 @@ export const addTask = (task) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchAllTasks())
} catch (error) {
......
......@@ -91,7 +91,19 @@ const tasksReduсer = (state = initialState, action) => {
})
return { ...state, loading: false, calendarTasks: newTasksWithInfoForCell };
case FETCH_ALL_TASKS_SUCCESS:
return { ...state, loading: false, tasks: action.tasks , projects: action.projects };
const newArrTasks = action.tasks.map((task)=>{
return {
...task,
authorName: task.author.displayName,
projectTitle: task.project.title,
accomplishTranslate: accomplishStatuses.find((status) => {
if (status.value === task.accomplish) {
return status
}
return null
}).text
}})
return { ...state, loading: false, tasks: newArrTasks , projects: action.projects };
case FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS:
const newArr = action.tasks.map((task)=>{
return {
......
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